Java Star (*) Pyramid Examples (Pattern5,6)


Java Pattern 5

/*

Output of the below program would be

*

***

*****

*******

*********

*/

import java.io.*;

public class JavaPyramidPattern5

{

public static void main(String args[])

{

int i, j, k=1;

for(i=0; i<5; i++)

{

for(j=0; j<k; j++)

{

System.out.print(“* “);

}

k = k + 2;

System.out.println();

}

}

}

output:

p5

 

 

 

 

 

 

 

 

 

Java Pattern 6

/*

Output of the below program would be

               *

           ***

       *****

   *******

*********

*/

 

import java.io.*;

public class JavaPyramidPattern6

{

public static void main(String args[])

{

int i, j, k=16, tim=1;

for(i=0; i<5; i++)

{

for(j=0; j<k; j++)

{

System.out.print(” “);

}

k = k – 4;

for(j=0; j<tim; j++)

{

System.out.print(“* “);

}

tim = tim + 2;

System.out.println();

}

}

}

output:

p6

 

 

 

 

 

 

 

 

 

 

More Example

Java Pyramid pattern 1,2

Java Pyramid Pattern 3,4

Java Pyramid Pattern 7,8

Java Pyramid Pattern 9,10

Comments are closed.