Skip to content

Commit

Permalink
Hollow Diamond in java
Browse files Browse the repository at this point in the history
Pattern for Hollow Diamond in java
  • Loading branch information
Khushi-Sarawagi authored Oct 29, 2024
1 parent b11dd3c commit e2fc1fe
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions JAVA/HollowDiammond.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
public class hollow {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();

// upper half of the pattern
for(int i=1;i<=n;i++){

for(int j=n-i;j>=0;j--){
System.out.print("*");
}

for(int k=2*(i-1);k>0;k--){
System.out.print(" ");
}
for(int l=n-i;l>=0;l--){
System.out.print("*");
}
System.out.println();
}
//lower half of the pattern
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
System.out.print("*");
}
for(int k=2*(n-i-1);k>0;k--){
System.out.print(" ");
}
for(int m=0;m<=i;m++){
System.out.print("*");
}
System.out.println();
}
}

}

0 comments on commit e2fc1fe

Please sign in to comment.