Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions lightdraw/PrintDiamondOfStars.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package javacodes.lightdraw;

import java.util.Scanner;

public class PrintDiamondOfStars {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Taking noOfRows value from the user

System.out.println("How Many Rows You Want In Your Diamond?");

int noOfRows = sc.nextInt();

// Getting midRow of the diamond

int midRow = (noOfRows) / 2;

// Initializing row with 1

int row = 1;

System.out.println("Here Is Your Diamond : ");

// Printing upper half of the diamond

for (int i = midRow; i > 0; i--) {
// Printing i spaces at the beginning of each row

for (int j = 1; j <= i; j++) {
System.out.print(" ");
}

// Printing j *'s at the end of each row

for (int j = 1; j <= row; j++) {
System.out.print("* ");
}

System.out.println();

// Incrementing the row

row++;
}

// Printing lower half of the diamond

for (int i = 0; i <= midRow; i++) {
// Printing i spaces at the beginning of each row

for (int j = 1; j <= i; j++) {
System.out.print(" ");
}

// Printing j *'s at the end of each row

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

System.out.println();

// Decrementing the row

row--;
}
}

}