//生成 0-100 随机数,直到生成 88 为止,停止循环! public class Test02 { public static void main(String[] args) { while (true){ int a =(int)(Math.random()*100)+1; //:生成0-100的随机数 (Math.random) if(a==88){ break; }else{ System.out.println(a); } } } }
![]() |
问题: 运行结果来看并不是到88结束循环,我在这里引用的是Math.Random生成0-100之间的数,感觉没有执行break语句,查看百度,都是用random下面的方法nextInt(int a),这两种有啥区别?