前后端之路程序员

如何用java在命令行打出心

2018-06-16  本文已影响5人  吃盖浇饭
image.png

System.out.println("1.第四题");        
        int x = 9;
        for (int i = 1; i <= x; i++) {
            for (int j = 1; j <= x - i; j++) {
            
                System.out.print(" ");      
                                                    
            }
            for (int k = 1; k <= 2 * i - 1; k++) {
                int num = 2 * i - 1;
                if(i < ((x / 2) + 2)) {                 
                    continue;
                    
                }else if(k>( num / 2 -(9 - i)) && k<(num / 2 + (11 - i))){
                    System.out.print(" ");
                    continue;
                }
                System.out.print("*");
            }
            if(i>4){
                System.out.println();
            }   
            Thread.sleep(100);
        }
        for (int i = 1; i < x; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(" ");
            }
            for (int k = 1; k <= 2 * (x - i)  - 1; k++) {
                System.out.print("*");
            }
            System.out.println();
            Thread.sleep(100);
        }
上一篇 下一篇

猜你喜欢

热点阅读