Number Patterns using loops in Java

前端 未结 7 2250
感动是毒
感动是毒 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:00

    Your inner for loop

    for (int j = (rows + 1 - i) ; j  > 0 ; j-- ){
        System.out.print(j);
    }
    

    will always count down to 1, because it keeps going until j is zero. Also, the number that the current row starts on will depend on the current row, because you used i in your assignment to j. To get pattern 1 both of those things will have to change.

提交回复
热议问题