Number Patterns using loops in Java

前端 未结 7 2117
感动是毒
感动是毒 2021-01-25 04:30

I have been trying different variations of for loops and have no clue how to make these patterns:

Pattern 1

54321
5432
543
54
5

Pattern

7条回答
  •  佛祖请我去吃肉
    2021-01-25 05:19

    The first program is:

    class timepass {
        public static void main() {
            for (int a = -1;a<=5;a++) {
                for(int b = 5; b >= a;b--) {
                    System.out.print("*");   
                }
                System.out.println();
                // enter code here
            }
        }
    }
    

    The second program is:

    class timepass {
        public static void main() {
            for(int i = 1;i<= 6;i++) {
                for(int j = 1;j<= i ;j++) {
                    System.out.print("*");
                }
                System.out.println();
            }
        }
    }
    

提交回复
热议问题