因为你的数太少,现在的CPU运行速度很快的 你的代码没贴完整 我自己修改了下弄了个完整的 输入了10000个整数 运行时间大概是110毫秒。
public class Test5 {
public static void main(String[] args) {
long begin = System.currentTimeMillis();
int[] s_array = new int[10000];
int n = s_array.length;
for (int i = 0; i < n; i++) {
s_array[i] = i;
}
for (int i = 0; i < n - 1; i++) {
int k = i;
for (int j = i + 1; j < n; j++) {
if (s_array[j] < s_array[k])
k = j;
}
if (k != i) {
int temp;
temp = s_array[i];
s_array[i] = s_array[k];
s_array[k] = temp;
}
}
long end = System.currentTimeMillis();
System.out.println();
System.out.print("排序结果:");
for (int i = 0; i < n; i++) {
System.out.print(s_array[i] + " ");
}
System.out.println();
System.out.println("选择排序法用时为:" + (end - begin));
System.out.println("选择排序法比较次数为:" + (n * (n - 1)) / 2);
}
}