47 讀取7個數(1—50)的整數值,每讀取一個值,程序打印出該值個數的*。


題目:讀取7個數(1—50)的整數值,每讀取一個值,程序打印出該值個數的*。 

 1    public class _047ReadNumberPrintStar {
 2 
 3     public static void main(String[] args) {
 4         readNumberPrintStar();
 5     }
 6 
 7     private static void readNumberPrintStar() {
 8         Scanner s = new Scanner(System.in);
 9         int n = 1, num;
10         while (n <= 7) {
11             do {
12                 System.out.println("請輸入一個1--50之間的整數:");
13                 num = s.nextInt();
14             } while (num < 1 || num > 50);
15             for (int i = 1; i <= num; i++) {
16                 System.out.print("*");
17             }
18             System.out.println();
19             n++;
20         }
21     }
22 }

 


免責聲明!

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



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