【王道JAVA】【程序 47 打印星號】

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

import java.util.Scanner;

public class WangDao {
	public static void main(String[] args){
		System.out.print("Input your number: ");
		Scanner scan = new Scanner(System.in);
		for (int i = 0; i < 7; i++) {
			int n = scan.nextInt();
			printStar(n);
			System.out.println();
		}
	}
	
	public static void printStar(int n) {
		for (int i = 0; i < n; i++) {
			System.out.print("*");
		}
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章