Printing *s as triangles in Java?

后端 未结 21 1920
囚心锁ツ
囚心锁ツ 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:25

    Question:

          *
         ***
        *****
    

    Answer:

        int i,a,j;
        i=5;
        while (i>=3)
        {
            a=1;
            while (a<=i)
            {
    
                System.out.print(" ");
                a++;
            }
            j=10;
            while (j/2>=i)
            {
                System.out.print("*");
                --j;
            }
            System.out.println("");
            i--;
        }   
    

    Enjoy!!

提交回复
热议问题