11智能在线
新记
编写一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 = "";
}
}
}
}
本回答被网友采纳
相似回答
大家正在搜
相关问题
编写程序,随机生成50个两位整数,按每行10个输出
java编程题编写一个程序随机生成20个1到100的正整数,...
Java编程,随机生成20个大于等于0并且小于100的整数,...
java编程题:随机产生20个50~100之间的整数,输出这...
用Java编写一程序,(1)随机产生200个三位的正整数,按...
Java程序编写:随机产生20个100以内的整数数组,显示出...
用java程序随机生成20个100以内的整数