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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM