import java.util.Random;
public class GetNum {
public static int i = 0;
public static void main(String[] args) {
Random r = new Random();
int arr[] = new int[10];
int temp = 0;
for (; i < 10;) {
temp = r.nextInt(100);//生成10个0-100的数
if (i == 0) {
arr[i] = temp;
i++;
} else {
for (int j = 0; j < i; j++) {
if (arr[j] == temp) {
break;
} else if (j == i - 1) {//判断所有的arr[j]是否都不等于temp,不等就把temp赋值给arr[i]
arr[i] = temp;
i++;
// break;
}
}
}
}
for (int n = 0; n < arr.length; n++) {//对你取的10个随机数排序
for (int j = n + 1; j < 10; j++) {
if (arr[n] > arr[j]) {
temp = arr[n];
arr[n] = arr[j];
arr[j] = temp;
}
}
System.out.println(arr[n]);
}
}
}
并插于一个任意数看不懂!!!
收起
作业帮用户
2017-11-16
举报