How to Print Pyramid 6 in Java


Here we may learn how to generate pyramid or triangle like given below with for loop.

***** **** *** ** * * ** *** **** *****

Source Code

package com.beginner.examples;

public class PyramidExample6 {

    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("");
		}
    	for(int m = 1; m<= 6 ; m ++)
    	{
			for(int n = 0; n < m; n ++)
			{
				System.out.print(n);
			}
			//line feed
			System.out.println("");
		}
    }
}

Output:

012345
01234
0123
012
01
0
0
01
012
0123
01234
012345
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments