Generate Pyramid Triangle Example in Java

 

Program to generate pyramid triangle example in java.

/**
 * Program to generate pyramid triangle example in java.
 * @author W3spoint
 */
public class GeneratePyramidTriangleExample {	
	static void generatePyramidTriangle(int rows){
		//Logic to generate pyramid triangle.
		 for(int i=1; i<= rows; i++){             
                    for(int j=0; j < i; j++){
                        System.out.print("*");
                    }            
                    //New line.
                    System.out.println("");
                 }
	}	
 
	public static void main(String args[]){ 
		//method call 
		generatePyramidTriangle(10); 
	}
}

Output:

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

Download this example.
 

Content Protection by DMCA.com
Please Share