选择排序:先确定第一个位置的值,再确定第二个位置的值。。。直到最后一个。

public class Test {
	public static void main(String[] args) {
		System.out.println("选择排序");
		int[] numbers = new int[5];
		numbers[0] = 5;
		numbers[1] = 10;
		numbers[2] = 1;
		numbers[3] = 8;
		numbers[4] = 2;
		sort(numbers);
		for(int i : numbers) {
			System.out.print(i + " ");
		}
	}
	
	public static void sort(int[] numbers) {
		for(int i = 0; i < numbers.length; i++) {
			for(int j = i + 1; j < numbers.length; j++) {
				if(numbers[i] > numbers[j]) {
					int temp = numbers[i];
					numbers[i] = numbers[j];
					numbers[j] = temp;
				}
			}
		}
	}
}