编写一JAVA程序,随机产生20个0-100之间的正整数,按每行5个数输出

如题所述

第1个回答  2011-06-20
Random random = new Random();
for(int i = 0; i < 20; i++) {
System.out.print(random.nextInt(100));
if((i + 1) % 5 == 0) {
System.out.println();
} else {
System.out.print(",");
}
}
第2个回答  2011-06-20
public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "";
for(int i = 1 ;i < 21 ;i++){
str = str+" "+Math.round(Math.random()*100);
if(i % 5 == 0 ){
System.out.println(str);
str = "";
}
}
}

}本回答被网友采纳
相似回答