-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiamond_Variable.java
More file actions
27 lines (26 loc) · 890 Bytes
/
Diamond_Variable.java
File metadata and controls
27 lines (26 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Scanner;
public class Diamond_Variable {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter Rows : ");
int len = input.nextInt();
int right = len;
int left = len;
for (int i = 1; i <= len; right++, left--, i++) {
for (int j = 1; j <= (2 * len - 1); j++) {
if ((j >= left) && (j <= right)) System.out.print("*");
else System.out.print(" ");
}
System.out.println();
}
left += 2;
right -= 2;
for (; left <= right; left++, right--) {
for (int k = 1; k <= (2 * len - 1); k++) {
if ((k >= left) && (k <= right)) System.out.print("*");
else System.out.print(" ");
}
System.out.println();
}
}
}