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