交换排序 错在哪里啊。
public class Swap {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//交换法
int[] score = new int[100];
//初始化数组
for (int i = 0; i <= score.length - 1; i++) {
score[i] = (int)(Math.random() * 100);
}
int temp ;//中间变量
int i ;
int j ;
for (i = 0; i < score.length - 1; i++) {
int min = i;//假设最小值
//找最小值
for (j = i + 1; j <= score.length - 1; j++) {
if (score[j] < min) {
min = j;
}
}
//交换最小值的位置
if (min != i) {
j--;
temp = score[i];
score[i] = score[j];
score[j] = temp ;
}
}
System.out.println("排序后的数组:");
for (int k = 0; k <= score.length - 1; k++) {
if (k % 10 == 0) {
System.out.println();
}
System.out.print(score[k]+"\t");
}
}
}