title: Insert number into ordered arrayList
body: <p>I have an interesting problem on how to insert any number into an ordered ArrayList. Lets say the user enters <code>[12,34,37,60,89]</code>; the method <code>addListElement()</code> should traverse the array to find the index where the new element will go.</p>
  
  <p>The user enters the number 50, the new array should be <code>[12,34,37,50,60,89]</code>. I used a for loop to traverse the ArrayList, but I'm not sure about my if() statement.</p>
  
  <pre><code>public void addListElement() {
      System.out.println("Add number to arrayList");
      Scanner scan = new Scanner(System.in);
      int number = scan.nextInt();
  
      int loc = 0;
      for (int i = 0; i &lt; aryList.size(); i++) {
          if (number &gt; 0 &amp;&amp; i &lt; loc) {
              loc++;
          }
      }
  
      aryList.add(loc, number);
      System.out.println(aryList.toString());
  }
  </code></pre>