楼上没考虑生成20个三位数,下面是正确的程序
import java.util.*;
public class Array {
public static void main(String[] args) {
ArrayList
Random rand = new Random();
for (int i = 0; i < 20; i++) {
int a = rand.nextInt(900) + 100;
arr.add(a);
}
for (Integer i : arr) {
System.out.println(i);
}
}
}
import java.util.*;
public class Array {
public static void main(String[] args) {
ArrayList
Random rand=new Random();
for(int i=0;i<20;i++){
int a=rand.nextInt(1000);
arr.add(a);
}
for(Integer i:arr){
System.out.println(i);
}
}
}
import java.util.*;
public class Array {
public static void main(String[] args) {
ArrayList
Random rand=new Random();
for(int i=0;i<20;i++){
int a=rand.nextInt(10),b=rand.nextInt(10),c=rand.nextInt(10);
int temp=a+b*10+c*100;
arr.add(temp);
}
for(Integer i:arr){
System.out.println(i);
}
}
}
呵呵有意思,三楼的朋友正解
咱给填上注释!
---------------------------------------------------------------------------------
import java.util.*;
public class Array {
public static void main(String[] args) {
//生成存储Integer类型的ArrayList链表
ArrayList
//调用随机函数
Random rand = new Random();
for (int i = 0; i < 20; i++) {
//生成随机数
//为每个生成的随机函数加上一百,因为这里的随机数
//有可能是一位或两位数,但最大是899
//最小可能是0
int a = rand.nextInt(900) + 100;
arr.add(a);
}
for (Integer i : arr) {
System.out.println(i);
}
}
}
楼上正解