pyramid star pattern in java

Introduction To JAVA

pyramid star pattern in java by using for loop  :

Question :  Print a simple pyramid star pattern in java by using the for loop,  we will understand how to print pyramid star pattern. The pattern is formed by using multiple for-loops and print statements.

 

Input :

Lets, consider our input is 7

so our total row n= 7;

pyramid pattern

Output :

Than we required output as shown in fig……………

 

  •  firstly  we create a class SimplePyramidPattern  than we create a method star

 

public class SimplePyramidPattern

public static void star(int n)

  • Declared the two veribale which is int type variable

int i;
int j;

  • After that we used two for loop with Star (*) print statement in the inner loop and outer loop we are providing the println statement the basic diffresnt between print and println is print statement print a star and stay on current line  but println statement is print the star and break current line and move on the next line.

 

for(i=0; i<n;i++) {
for(j=0; j<=i; j++) {
System.out.print(“* “);
}
System.out.println();
}

  • The last step is create a main method and declared how many row required, in our condition we required  only 7 rows so  we put values of n is 7 and called star method.

 

public static void main(String args[]) {
int n=7;
star(n);

 

 

 

 

 

 

 

Actual Full Code :

pyrimid code

Join Telegram : Click Here

 

All Full Stack Java Study Material

 

 

Job For Fresher

 

Share This Information To Your Friends and Your College Group’s, To Help Us !