-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp10.java
More file actions
37 lines (31 loc) · 1.02 KB
/
p10.java
File metadata and controls
37 lines (31 loc) · 1.02 KB
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
28
29
30
31
32
33
34
35
36
37
/**
* Write an interactive program to print a diamond shape. For example, if user enters the number 3,
the diamond will be as follows
*
* *
* * *
* *
*
*/
import java.util.Scanner;
public class p10 {
public static void printPyramid(int diamondNum, int i) {
int space = diamondNum - i;
for(int j = 0; j < space; j++)
System.out.print(" ");
for(int k = 0; k <= i; k++)
System.out.print("* ");
System.out.println("");
}
public static void main(String args[]) {
Scanner s1 = new Scanner(System.in);
System.out.println("Enter number : ");
int diamondNum = s1.nextInt();
for(int i = 0; i < diamondNum; i++) {
printPyramid(diamondNum, i);
}
for(int i = diamondNum - 1; i >= 0; i--) {
printPyramid(diamondNum, i);
}
}
}