Java经典编程题50道之四十七

读取7个数(1~50)的整数值,每读取一个值,程序打印出该值个数的*。

public class Example47 {
    public static void main(String[] args) {
        int[] a = { 10, 7, 6, 15, 4, 3, 20 };
        display(a);
    }

    public static void display(int[] a) {
        System.out.print("读取的整数有:");
        for (int r : a) {
            System.out.println(r + " ");
        }
        for (int i = 0; i < a.length; i++) {
            System.out.print("打印" + a[i] + "个*:");
            for (int j = 0; j <= a[i]; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

posted @ 2017-06-10 21:39  本宫在,尔等都是妃  Views(118)  Comments(0Edit  收藏  举报