Java Generate Pyramid For a Given Number

 

Program to generate pyramid for a given number example in java.

/**
 * Program to generate pyramid for a given number example in java.
 * @author W3schools360
 */
public class GeneratePyramidExample {	
	static void generatePyramid(int lines, int numDiff){
		 int y = 0;         
                 for(int i=0; i<= lines; i++){                
                   for(int j=1; j <= i ; j++){
                         System.out.print(y + "\t");
                         y = y + numDiff;
                   }                
                   System.out.println("");
               }
	}	
	
	public static void main(String args[]){ 
		//method call 
		generatePyramid(6, 3); 
	}
}

Output:

0	
3	6	
9	12	15	
18	21	24	27	
30	33	36	39	42	
45	48	51	54	57	60