Printing *s as triangles in Java?

后端 未结 21 1886
囚心锁ツ
囚心锁ツ 2020-11-30 11:41

My assignment in my Java course is to make 3 triangles. One left aligned, one right aligned, and one centered. I have to make a menu for what type of triangle and then input

21条回答
  •  借酒劲吻你
    2020-11-30 12:27

        for(int i=1;i<=5;i++)
        {
            for(int j=5;j>=i;j--)
            {
                System.out.print(" ");
            }
            for(int j=1;j<=i;j++)
            {
                System.out.print("*");
            }
    
            for(int j=1;j<=i-1;j++)
            {
                System.out.print("*");
            }
            System.out.println("");
        }
    
     *
    ***
    



提交回复
热议问题