-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern-14.java
More file actions
30 lines (20 loc) · 835 Bytes
/
pattern-14.java
File metadata and controls
30 lines (20 loc) · 835 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
// Star Pattern 14 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++){
// for first and last columns
if(col==1 || col==n)
System.out.print("*\t");
// for second half rows and diagonal columns
else if( row >= n/2+1 && (col == row || col == n-row+1) )
System.out.print("*\t");
else System.out.print("\t");
}
System.out.println(); // printing new line
}
}
}