java输出菱形

解题思路:
高中数学知识
这里写图片描述

public static void show(int length) {
        for (int x = -length; x <= length; x++) {
            for (int y = -length; y <= length; y++) {
                if (((y - x) <= length && (y - x) >= -length && ((y + x) >= -length && (y + x) <= length))) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        show(10);
    }

猜你喜欢

转载自blog.csdn.net/u014645652/article/details/78301634