How to Generate Pyramid or Triangle in Java


The example aims to generate pyramid or triangle in Java.

Source Code

package com.beginner.examples;

public class PyramidExample3 {

    public static void main(String[] args){
    	
    	for(int m = 1; m<= 6 ; m ++)
    	{
			for(int n = 0; n  0 ; m --)
    	{
			for(int n = 0; n < m; n ++)
			{
				System.out.print("*");
			}
			//line feed
			System.out.println("");
		}
    }
}

Output:

*
**
***
****
*****
******
******
*****
****
***
**
*
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments