-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern7.java
More file actions
38 lines (36 loc) · 937 Bytes
/
Pattern7.java
File metadata and controls
38 lines (36 loc) · 937 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
28
29
30
31
32
33
34
35
36
37
38
import java.util.Scanner;
public class Pattern7 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("enter row");
int n=s.nextInt();
int row=1;
int space1=n-row;
int space2=0;
while (row<=2*n-1){
int k=space1;
int c=space2;
while (k>0){
System.out.print(" ");
k--;
}
System.out.print("*");
while (c>0){
System.out.print(" ");
c--;
}
if (row!=1 && row!=2*n-1)
System.out.print("*");
if (row<n) {
space2 = 2*(row)-1;
space1--;
}
else {
space2 = 2*(2*n-row-2)-1;
space1++;
}
System.out.println();
row++;
}
}
}