Java 产生一个大于等于200,小于300的随机数,且是10的整数倍

 1 public class Random200_300 {
 2     public static void main(String[] args) {
 3         int r1 = 0;
 4         while (true) {
 5             r1 = (int)(Math.random() * 10) * 10 + 200;
 6             if ((200 <= r1) && (r1 < 300)) {
 7                 System.out.println(r1);
 8             } else {
 9                 System.out.println("Error!");
10                 break;
11             }
12             
13             try {
14                 Thread.sleep(200);
15             } catch (InterruptedException e) {
16                 e.printStackTrace();
17             }
18         }
19     }
20 }

猜你喜欢

转载自www.cnblogs.com/Satu/p/9854987.html