JAVA编程题:使用排序算法将数列进行从大到小排序: 17, 10, 26, 50, 14, 10, 53, 20, 64, 83。
代码如下: public class MaoPao {
public static void main(String[] args) {
int array[] = { 17, 10, 26, 50, 14, 10, 53, 20, 64, 83 };
MaoPao mySort = new MaoPao();
mySort.bubbleSort(array);
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
}
public void bubbleSort(int[] array) {
int temp;
for (int i = 0; i < array.length; i++) {// 趟数
for (int j = 0; j < array.length - i - 1; j++) {// 比较次数
if (array[j] < array[j + 1]) {
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
}
}
若满意请采纳。