Skip to content

Commit

Permalink
diamond printing using for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
suhanigupta23 authored Feb 3, 2024
1 parent b450003 commit 5353cbd
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions diamondprinting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.*;

public class Program
{
public static void main(String[] args)
{
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();

for (int i = 1; i <= (n + 1) / 2; i++)
{
for (int j =(n+1)/2-i ; j>0; j--) {
System.out.print(" ");
}

for (int k = (2 * i - 1); k > 0; k--) {
System.out.print("*");
}

System.out.println();
}
for (int i = (n+1)/2; i>=1 / 2; i--)
{
for (int j =1 ; j<=(n+1)/2-i; j++) {
System.out.print(" ");
}

for (int k =1; k <=2*i-1; k++) {
System.out.print("*");
}

System.out.println();
}
}
}

0 comments on commit 5353cbd

Please sign in to comment.