Hollow Rhombus Pattern

 import java.util.*;


public class practice {

    public static void rhombus(int n){

        for(int row=1;row<=n;row++){

            for(int space=1;space<=n-row;space++){

                System.out.print(" ");

            }

            for(int col=1;col<=n;col++){

                if(row==1||row==n||col==1||col==n){

                    System.out.print("*");
                }
                else{

                    System.out.print(" ");
                }


               
            }

            System.out.print("\n");


        }
       

    }

    public static void main(String[] args) {

        Scanner s =new Scanner(System.in);

        int n;
        System.out.println("Enter the no of stars on rhombus");

        n=s.nextInt();
        rhombus(n);

           
    }

}

Output :=

Comments

Popular posts from this blog

Convert first letter to capital letter in java

Stair case traversal search

Time conversion into IST