java输出菱形

来源:互联网 发布:视频剪辑软件学习 编辑:程序博客网 时间:2024/05/21 09:19

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

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);    }