int temp;
int values[] = new int[10];
/**
* 产生10个随机数
*/
for (int i = 0; i < 10; i++) {
int b = (int) (Math.random() * 40) + 60;// 产生0-1000的整数随机数
System.out.print(b + " ");
values[i] = b;
}
/**
* 冒泡排序
*/
for (int i = 0; i < values.length; ++i) {
for (int j = 0; j < values.length - i - 1; ++j) {
if (values[j] > values[j + 1]) {
temp = values[j];
values[j] = values[j + 1];
values[j + 1]=temp;
}
}
}
/**
* 排序后输出
*/
System.out.println();
System.out.println("排序后从大到小:");
for (int i = values.length-1; i >=0 ; i--) {
System.out.print(values[i]+" ");
}
public class random {
public static void main(String[] args) {
int[] a = new int[10];
int n = 0;
while (n < 10) {
int b = (int) (Math.random() * 100) + 1;
if (b >= 60) {
a[n] = b;
n++;
}
}
System.out.print("生成[60~100]随机数为:");
for (int c : a) {
System.out.print(c + " ");
}
int b;
for (int i = 0; i < 10; i++) {
for (int j = i + 1; j < 10; j++) {
if (a[i] < a[j]) {
b = a[i];
a[i] = a[j];
a[j] = b;
}
}
}
System.out.print("\r\n排序结果为:");
for (int c : a) {
System.out.print(c + " ");
}
}
}
这种排序我不知道是不是选择排序? 能排