-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiamondPattern.java
34 lines (30 loc) · 961 Bytes
/
DiamondPattern.java
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
package patternprograames;
import java.util.Scanner;
public class diamondPattern {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the number of rows you want to print:- ");
int rows = s.nextInt();
// for upper portion first
int mid = (rows+1)/2;
for(int i = 1;i<=mid;i++){
for(int spaces = 1;spaces<=mid-i;spaces++){
System.out.print(" ");
}
for(int j = 1;j<=(2*i)-1;j++){
System.out.print("*");
}
System.out.println();
}
// now for lower part
for(int i = 1;i<=mid-1;i++){
for(int spaces = 1;spaces<=i;spaces++){
System.out.print(" ");
}
for(int j = 1;j<=(mid-i)*2-1;j++){
System.out.print("*");
}
System.out.println();
}
}
}