Program to print number triangle in java | Pattern Program - Math Traders

Latest

Program to print number triangle in java | Pattern Program



 class NumberDemo{

public static void main(String[] args) {

int i, j;

for (i=1; i<=5 ;i++ ) {                                 // Loop To Print Rows

for (j=1; j<=i ; j++ ) {                         // Loop To Print Columns 

System.out.print(j +" ");             // Prints value of 'j' after each iteration in the same line

}

System.out.println();                           // brings cursor in new line.

}

}

}


Output:

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

number triangle in java

No comments:

Post a Comment