title: Sort Array with two loops Implementation
body: <p>I am new with Java.
  I try to do one of my assignment, but i can not figure out why my result still can not sort.</p>
  
  <p>I have a prompt value(argument) 20 10 30 60 55, and i want to sort it.
  I wrote two loops, and converted prompt value (which is string) to Integer.</p>
  
  <p>Result: ( It is not sorted)</p>
  
  <blockquote>
    <p>20
    10
    30
    60
    55
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
        at question2.SortedArray.main(SortedArray.java:29)</p>
  </blockquote>
  
  <p>This is the code i wrote:</p>
  
  <pre><code>int temp = 0;
      int array[] = null;
      int array2[];
  
  
      for(int i=0; i&lt;args.length; i++){
          int a = Integer.parseInt(args[i]);
           array = new int[a];
          for(int j=0; j&lt;args.length; j++){
              int b = Integer.parseInt(args[i]);
              array2 = new int[b];
              if(array[i]&gt;array2[j])
                  temp = array2[j];
                  array2[j] = array[i];
                  array[i] = temp;
  
  
          }
      }
      for (int i = 0; i &lt; array.length; i++)
      {
                System.out.println(args[i].toString());
      }
  </code></pre>
  
  <p>I could understand this code i fould online below</p>
  
  <pre><code>int tempVar;
          for (int i = 0; i &lt; numbers.length; i++)
          {
                   for(int j = 0; j &lt; numbers.length; j++)
                   {
                           if(numbers[i] &gt; numbers[j])
                           {
                           tempVar = numbers [j ];
                           numbers [j]= numbers [i];
                           numbers [i] = tempVar;
                           }
                   }
          }
          for (int i = 0; i &lt; numbers.length; i++)
          {
                    System.out.print(numbers[i]+" ");
          }
  
  }
  </code></pre>