-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern-13.java
43 lines (31 loc) · 1.35 KB
/
pattern-13.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
35
36
37
38
39
40
41
42
43
// Pattern 13 Solution
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt(); // n should be odd
for(int row=1; row<=n; row++){
for(int col=1; col<=n; col++){
if(row == 1){ // first row
if( col <= n/2+1 || col == n ) System.out.print("*\t");
else System.out.print("\t");
}
else if(row <= n/2){ // between first and middle row
if( col == n/2+1 || col == n ) System.out.print("*\t");
else System.out.print("\t");
}
else if(row == n/2 + 1) // middle row
System.out.print("*\t");
else if(row < n){ // between middle and last row
if( col == 1 || col == n/2+1 ) System.out.print("*\t");
else System.out.print("\t");
}
else{ // last row
if( col == 1 || col >= n/2+1 ) System.out.print("*\t");
else System.out.print("\t");
}
}
System.out.println(); // printing new line
}
}
}