Math.random()没有执行循环的问题
public class random_word{public static void main(String[]args){
int x=3;
String[]wordlistone={"Editor","Alan","Rusbridger","said","July"};
String[]wordlisttwo={"it","was","forced","to","destroy","the","computer"};
String[]wordlistthree={"hard","drives","storing","the","information","in"};
int onelength=wordlistone.length;
int twolength=wordlisttwo.length;
int threelength=wordlistthree.length;
while(x>0){
int rand1=(int)(Math.random()*onelength);
int rand2=(int)(Math.random()*twolength);
int rand3=(int)(Math.random()*threelength);
String sentence=wordlistone[rand1]+" "+wordlisttwo[rand2]+" "+wordlistthree[rand3];
System.out.println("What we need is a "+ sentence);
x=x-1;}
}
}
加了whlie以后验证出来错误说while(x>0){后面少个分号
换大小写都没用 如果改成if(x>0)则只有一次随机选取之后的输出结果 没有循环
本意是想让他循环3次出来3种随机选择的词语搭配
新学JAVA。。不知道怎么搞。。求教- -