-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPattern5.java
More file actions
32 lines (31 loc) · 775 Bytes
/
Pattern5.java
File metadata and controls
32 lines (31 loc) · 775 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
import java.util.Scanner;
public class Pattern5 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("enter rows- ");
int n=s.nextInt();
int row=1;
while (row<=2*n-1){
int space;
int col;
if (row<=n){
space=n-row;
col=2*row-1;
}
else {
space=row-n;
col=2*(2*n-row)-1;
}
while (space>0){
System.out.print(" ");
space--;
}
while (col>0){
System.out.print("*");
col--;
}
System.out.println();
row++;
}
}
}