Sorting random non-repeating numbers I am working on a program in which 10000 random non-repeating numbers are selectively sorted into ascending order"

import java.util.Random;


public class Sorting {
    public static void main (String[] args){
        //Here, we initiate an array with the integers
        //1 through 10,000 in order.
        Random rgen = new Random();
        int[] intArray = new int[10000];
        for (int i=0; i&lt;10000; i++) {
            intArray[i] = i+1;
        }
        //Here, we randomize the positions.
        for (int i=0; i&lt;10000; i++) {
            int randomPosition = rgen.nextInt(10000);
            int temp = intArray[i];
            intArray[i] = intArray[randomPosition];
            intArray[randomPosition] = temp;
        }
        //Here, we check for the maximum in the 
        //unsorted section of the list.
        int max;
        for (int i=9999; i&gt;=0; i--) {
            max = i;
            for (int j=i-1; j&gt;=0; j--)
                if (intArray[j]&gt;intArray[max]) {
                    max = j;
                }
            //Here, we swap the positions of the 
            //maximum and the last value in the 
            //unsorted section of the list.
            if (max != i) {
                int tmp = intArray[i];
                intArray[i] = intArray[max];
                intArray[max] = tmp;
            }
        }
        //Here, we output the result.
        for (int k=0; k&lt;10000; k++) {
            System.out.println(intArray[k]);
        }
    }
}
I tested it and it works as it should. I would only like to remark a couple of things. 

You may want to split your long commented function into shorter ones:


static int[] InitArray(int length){...}
static int[] SelectionSort(int[]arr){...}
static void Swap(int[]arr, int i, int j){...}
print the result in the main(), as you do know.


This makes your code easier to read and easier to reuse.

Another thing I'd remove is the if(max != i). I'd rather make the swap every time.  If you look carefully, there's small chance that you do this operation unnecessarily, and when you do do it, it won't harm you. 

Note: If you keep doing the swap as you do now, you won't have any problem by removing the if. However, if you modify it to make the swap without a temp variable, it might go wrong.