public class SelectionSort { public static void selectionSort(int[] numArr) { int smallestIndex; // Stores the index of the smallest number for(int i = 0; i < numArr.length; i++) { smallestIndex = i; // Lowest index goes into smallestIndex for(int j = i + 1; j < numArr.length; j++) { // Find the smallest number and index of that number in numArr if(numArr[j] < numArr[smallestIndex]) { smallestIndex = j; } } int temp = numArr[i]; numArr[i] = numArr[smallestIndex]; numArr[smallestIndex] = temp; } } public static void main(String[] args) { int[] nums = {5, 6, 2, 10, 4}; System.out.print("Unsorted array : "); PrintArray.printIntArray(nums); selectionSort(nums); System.out.print("Sorted array : "); PrintArray.printIntArray(nums); } }