title: Java : Sort integer array without using Arrays.sort()
body: <p>This is the instruction in one of the exercises in our Java class. Before anything else, I would like to say that I 'do my homework' and I'm not just being lazy asking someone on Stack Overflow to answer this for me. This specific item has been my problem out of all the other exercises because I've been struggling to find the 'perfect algorithm' for this.</p>
  
  <blockquote>
    <p>Write JAVA program that will input 10 integer values and display either in ascending or descending order. Note: Arrays.sort() is not allowed.</p>
  </blockquote>
  
  <p>This is the code I have come up with, it works but it has one obvious flaw. If I enter the same value twice or more, for example:</p>
  
  <blockquote>
    <p>5, 5, 5, 4, 6, 7, 3, 2, 8, 10</p>
  </blockquote>
  
  <p>Only one of the three 5s entered would be counted and included in the output. The output I get (for the ascending order) is: </p>
  
  <blockquote>
    <p>2 3 4 5 0 0 6 7 8 10.</p>
  </blockquote>
  
  <pre><code>import java.util.Scanner;
  
  public class Exer3AscDesc
  {
      public static void main(String args[])
      {
          Scanner scan = new Scanner(System.in);
          int tenNums[]=new int[10], orderedNums[]=new int[10];
          int greater;
          String choice;
  
          //get input
          System.out.println("Enter 10 integers : ");
          for (int i=0;i&lt;tenNums.length;i++)
          {
              System.out.print(i+1+"=&gt; ");
              tenNums[i] = scan.nextInt();
          }
          System.out.println();
  
          //imperfect number ordering algorithm
          for(int indexL=0;indexL&lt;tenNums.length;indexL++)
          {
              greater=0;
              for(int indexR=0;indexR&lt;tenNums.length;indexR++)
              {
                  if(tenNums[indexL]&gt;tenNums[indexR])
                  {
                      greater++;
                  }
              }
              orderedNums[greater]=tenNums[indexL];
          }
  
          //ask if ascending or descending
          System.out.print("Display order :\nA - Ascending\nD - Descending\nEnter your choice : ");
          choice = scan.next();
  
          //output the numbers based on choice
          if(choice.equalsIgnoreCase("a"))
          {
              for(greater=0;greater&lt;orderedNums.length;greater++)
              {
                  System.out.print(orderedNums[greater]+" ");
              }
          }
          else if(choice.equalsIgnoreCase("d"))
          {
              for(greater=9;greater&gt;-1;greater--)
              {
                  System.out.print(orderedNums[greater]+" ");
              }
          }
      }
  }
  </code></pre>