public class Diamond {

public static void main(String[] args) {
    int n = 4;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            System.out.print(" ");
        }
        for (int j = 0; j < i + 1; j++) {
            System.out.print("* ");
        }
        System.out.println();
    }
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < i + 1; j++) {
            System.out.print(" ");
        }
        for (int j = 0; j < n - i - 1; j++) {
            System.out.print("* ");
        }
        System.out.println();
    }
}

}

// 输出结果: // * // * * // * * * // * * * * // * * * // * * //

java入门练习打印一个菱形效果如下

原文地址: https://www.cveoy.top/t/topic/cpBG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录