如何产生10个100之内的随机整数输出,并把这10个数按从小到大的顺序输出。
代码如下:
public class Main {
public static void main(String args[]) {
int math[] = new int[10];
for (int i = 0; i < 10; i++) {
math[i] = (int) (Math.random() * 100);
System.out.print(math[i] + " ");
}
System.out.println();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (math[i] < math[j]) {
int l = math[i];
math[i] = math[j];
math[j] = l;
}
}
}
for (int i = 0; i < 10; i++) {
System.out.print(math[i] + " ");
}
}
}
运行结果: