A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

import java.util.Scanner;
class ouShu {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入一个0-20的偶数");
                int i = sc.nextInt();
                for (int x = 1;x <= i ;x++ ) {
                        for (int y = 1;y <= i ;y++ ) {
                                if(x <= i/2){             //<=  整个图形的一半,
                                        if (y <= x || y > i-x) {
                                                System.out.print("* ");
                                        }else{
                                                System.out.print("- ");
                                        }
                                }else {
                                        if (y <= i-x || y > x) {
                                                System.out.print("* ");
                                        }else
                                                System.out.print("  ");
                                        }
                        }
                        System.out.println();
                }

        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马