4、循环产生一个1-100的随机数,若随机数是50,输出随机数并终止程序,否则继续
package org.lanqiao.proj.java1.j03_ifFor;
public class Task4 {
public static void main(String[] args) {
while(true) {
double num = Math.random(); //num >= 0.0 && num < 1.0
int randomNum = (int)(num * 100) + 1;
if(50 == randomNum) {
System.out.println("随机数是50,程序结束!");
break;
}
System.out.println(randomNum);
}
}
}