Through this example, we may see how to generate pyramid or triangle like given below with for loop.
12345 1234 123 12 1
Source Code
package com.beginner.examples;
public class PyramidExample5 {
public static void main(String[] args){
for(int m = 6; m> 0 ; m --)
{
for(int n = 0; n < m; n ++)
{
System.out.print(n);
}
//line feed
System.out.println("");
}
}
}
Output:
012345
01234
0123
012
01
0