title: Does not print out the last number for array using for loops
body: <p>The result gives me this but does not print out the last int (200). I add some random numbers in the main method and the by using the for loops it puts them in order. However, it completely ignores the last (greatest) integer, which is 200. How can I fix this?</p>
  <pre><code>0: 13
  1: 21
  2: 25
  3: 44
  4: 50
  5: 63
  6: 88
  7: 99
  8: 100
  </code></pre>
  <p>Here is the main method where I add random integers.</p>
  <pre><code>
      public static void main(String[] args) {
  
          SortedIntList myList = new SortedIntList(10);
  
          myList.add(100);
          myList.add(50);
          myList.add(200); // Does not print this line
          myList.add(25);
          myList.add(13);
          myList.add(63);
          myList.add(21);
          myList.add(99);
          myList.add(88);
          myList.add(44);
          System.out.println(myList);
      }
  }
  </code></pre>
  <p>Here is the for loop method to print all the integers sorted in order from least to greatest. It sets them in order just fine, it just does not add 200 for some reason.</p>
  <pre><code>  public void add(int value) {
          if (numElements == list.length) {
              System.out.println(&quot;Can't add, list is full&quot;);
          } else {
              if (numElements == 0) {
                  list[numElements] = value;
                  numElements++;
              } else {
                  int oldValue = 0;
                  boolean flag = false;
                  for (int i = 0; i &lt; numElements; i++) {
                      if (value &lt; list[i] &amp;&amp; !flag) {
                          oldValue = list[i];
                          list[i] = value;
                          flag = true;
                          if (numElements + 1 != list.length) {
                              numElements++;
                          }
                      } else if (flag) {
                          int temp = list[i];
                          list[i] = oldValue;
                          oldValue = temp;
                          if (i == list.length - 1) {
                              list[i + 1] = temp;
                              numElements++;
                              break;
                          }
                          if (temp == 0) {
                              break;
                          }
                          if (numElements + 1 != list.length) {
                              numElements++;
                          }
                      }
                     else if (i == numElements - 1) {
                          list[numElements] = value;
                          if (numElements + 1 != list.length) {
                              numElements++;
                              break;
                          }
                      }
                  }
              }
          }
      }
  </code></pre>
  <p>This is what the toString method looks like</p>
  <pre><code> public String toString()
      {
          String returnString = &quot;&quot;;
          for (int i = 0; i &lt; numElements; i++) {
              returnString += i + &quot;: &quot; + list[i] + &quot;\n&quot;;
          }
  
          return returnString;
      }
  </code></pre>