package cn.javageiyegun.demo04;
public class Test {
public static void main(String[] args) {
//随机生成1-100的一个数,直到生成97这个数,一共用了多少次
//[random-->返回带正号的double值,该值大于大于0.0且小于1.0]
//提示使用(int)(Math.random() * 100) + 1
int count = 0;
while(true){
int j = (int)(Math.random() * 100) + 1;
if (j != 97){
count++;
} else {
break;
}
}
System.out.println(count);
}
}
第四章 2.随机生成数(额外补充)
最新推荐文章于 2024-09-15 19:46:31 发布