Qn: Write the program logic to print stars as follows using java
       
* * * * * * * * *        
  * * * * * * *  
    * * * * *   
      * * *    
        * 
      * * *              
    * * * * *    
  * * * * * * *  
* * * * * * * * *
-By Admin, Last Update On 30th May,2019 10:16 am

இதை கீழ்க்கண்டவாறு இரண்டாக பிரித்து. அவற்றின் logic-களை ஒன்றாக இணைத்தால் நமக்கு தேவையான output கிடைத்துவிடும்.

part-1
* * * * * * * * *
  * * * * * * *  
    * * * * *   
      * * *    
        *

        
        *        
      * * *      
    * * * * *    
  * * * * * * *  
* * * * * * * * *
part-2

இவற்றை ஒன்றாக இணைக்கும்போது part-1ல் உள்ள கடைசி row மற்றும் part-2ல் உள்ள முதல் row இவற்றில் எதாவது ஒன்றை மட்டும் தான் எடுத்துகொள்ளவேண்டும்.

//part-1 logic
for(int row=n;row>=1;row--){
     for(int s=1;s<=(n-row);s++){
         Logic to print space here..
    }
    for(int col=1;col<=(row*2)-1;col++){
        Logic to print stars here..
    }
    System.out.println();
}
//part-2 logic
for(int row=2;row<=n;row++){
     for(int s=1;s<=(n-row);s++){
         Logic to print space here..
    }
    for(int col=1;col<=(row*2)-1;col++){
        Logic to print stars here..
    }
    System.out.println();
}

Complete Program

import java.util.Scanner;
public class PrintPattern{
    public static void main(String args[]){
        Scanner sn=new Scanner(System.in);
        System.out.print("Enter how many rows you want: ");
        int n=sn.nextInt();
        //part-1
        for(int row=n;row>=1;row--){
            for(int s=1;s<=(n-row);s++){
                System.out.print(" ");
            }
            for(int col=1;col<=(row*2)-1;col++){
                System.out.print("*");
            }
            System.out.println();
        }
        //part-2
        for(int row=2;row<=n;row++){
            for(int s=1;s<=(n-row);s++){
                System.out.print(" ");
            }
            for(int col=1;col<=(row*2)-1;col++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
Output:
Enter how many rows you want: 5
* * * * * * * * *
  * * * * * * *  
    * * * * *   
      * * *    
        *        
      * * *      
    * * * * *    
  * * * * * * *  
* * * * * * * * *

Pgcomments

Comments