FmD4FRX3FmXvDZXvGZT3FRFgNBP1w326w3z1NBMhNV5=

Video

items

Advanced Level Star Pattern Programs In Java

Advanced Level Star Pattern Programs In Java

In this post, you will get to see Advance Level Star Pattern Programs In Java. In the previous post, I have solved the examples of basic star patterns in java. If you haven't seen that post before, check it out at the link below. 

But before learning star patterns, you need to know about the loop, nested loop and if-else statements. If you don't know about it, you can learn it easily from the following link.

In this, we have taught you how to print the Star Pattern program from Java. This will make your loops concepts stronger. And these programs are going to be very beneficial for beginners or freshers.

The Java interview often asks about the pattern program. Therefore, students in IT need to know more about pattern programs.

We are going to do all the programs dry run. So you will notice the flow of code. You need to download the dry run excel file from the link given below the program.

Three types of patterns are printed in the JAVA programming language.

  1. Star Pattern
  2. Number Pattern
  3. Character Pattern
The first two examples of this were given for practice in the previous post, this post contains their solutions.

In all these programs you can take value from the user. Using Scanner or BufferedReader.

1. Sandglass Java Star Pattern Program
public class PatternPrograms{
public static void main(String[] args){ int rows = 5; for (int i= 0; i<= rows-1 ; i++){ for (int j=0; j <i; j++){ System.out.print(" "); } for (int k=i; k<=rows-1; k++) { System.out.print("*" + " "); } System.out.println(); } for (int i= rows-1; i>= 0; i--){ for (int j=0; j< i ;j++){ System.out.print(" "); } for (int k=i; k<=rows-1; k++){ System.out.print("*" + " "); } System.out.println(); } } }
Output:
Star Pattern Programs In Java











2. Diamond Pattern Program In Java.
  public class DiamondDemo  
 {  
   public static void main(String args[])   
   {  
     int i, j, space = 1;  
     int rows = 4;  
     space = rows - 1;  
     for (j = 1; j <= rows; j++)   
     {  
       for (i = 1; i <= space; i++)   
       {  
         System.out.print(" ");  
       }  
       space--;  
       for (i = 1; i <= 2 * j - 1; i++)   
       {  
         System.out.print("*");          
       }  
       System.out.println("");  
     }  
     space = 1;  
     for (j = 1; j <= rows - 1; j++)   
     {  
       for (i = 1; i <= space; i++)   
       {  
         System.out.print(" ");  
       }  
       space++;  
       for (i = 1; i <= 2 * (rows - j) - 1; i++)   
       {  
         System.out.print("*");  
       }  
       System.out.println("");  
     }  
   }  
 }  
Output:
Advance Level Star Pattern Programs In Java
3. Right Pascal’s Triangle Pattern Program In Java.
 public class TechandFun  
 {  
   public static void main(String[] args)  
   {  
     int rows = 4;   
     for (int i= 0; i<= rows-1 ; i++)  
     {  
       for (int j=0; j<=i; j++) { System.out.print("*"+ " "); } System.out.println(""); } for (int i=rows-1; i>=0; i--)  
     {  
       for(int j=0; j <= i-1;j++)  
       {  
         System.out.print("*"+ " ");  
       }  
       System.out.println("");  
     }  
   }  
 }  
Output:          
Star Pattern Programs In Java











4. Left Pascal’s Triangle Pattern Program In Java.
  public class TechandFun  
 {  
   public static void main(String[] args)  
   {  
     int rows = 5;   
     for (int i= 1; i<= rows ; i++)  
     {  
       for (int j=i; j <rows ;j++)        
     {  
         System.out.print(" ");  
       }  
       for (int k=1; k<=i;k++) { System.out.print("*"); } System.out.println(""); } for (int i=rows; i>=1; i--)  
     {  
       for(int j=i; j<=rows;j++)  
       {  
         System.out.print(" ");  
       }  
       for(int k=1; k<i ;k++)   
       {  
         System.out.print("*");  
       }  
       System.out.println("");  
     }  
   }  
 }  
Output:
Star Pattern Programs In Java
5. Down Triangle Pattern Program In Java.
 public class TechandFun{  
   public static void main(String[] args){  
     int rows = 5;    
     for (int i=rows; i>= 1 ; i--){  
       for (int j = i; j < rows ; j++) {  
         System.out.print(" ");  
       }    
       for(int k = 1; k <= (2*i -1) ;k++) {  
         if( k==1 || i == rows || k==(2*i-1)) {  
           System.out.print("*");  
         }  
         else {  
           System.out.print(" ");  
         }  
       }  
       System.out.println("");  
     }  
   }  
 }  
Output:
Advance Level Star Pattern Programs In Java

Practice well and become an expert in Java programming. With the help of these advanced level star pattern programs, you can solve the next pattern yourself.

JAVA Star Pattern Programs Examples for Practice

Solve the following Java Star Pattern programs on your skills. And if not, the solutions will be found in the next post.

1. Hollow Square Star Pattern in java.

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

2. Rhombus Star Pattern in java

      * * * * *   
     * * * * *   
    * * * * *   
   * * * * *   
  * * * * *   
If there are 5 comments on this post, then the solution of examples will be given. Make quick comments for the solution.                                                         
                                                          Home | Top of the page

0/Post a Comment/Comments

73745675015091643