Number patterns are similar to ‘symbol’ patterns. The logic is similar to Right Angle Triangle Pattern. Let us see the code for number pattern.
public class Tech4Humans {
public static void main(String[] args) {
// length of triangle
int size = 5;
for (int i = 0; i < size; i++) {
for (int j = 0; j <= i; j++) {
System.out.print((j+1)+" ");
}
System.out.println();
}
}
}
Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
To understand code more easily debug using pen and paper. To find out simple way to debug visit RIGHT WAY TO DEBUG CODE USING PEN AND PAPER.