-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPattern6.java
More file actions
67 lines (55 loc) Β· 1.34 KB
/
Copy pathPattern6.java
File metadata and controls
67 lines (55 loc) Β· 1.34 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package day2;
import java.util.Scanner;
public class Pattern6 {
/*
n = 6 ( >= 2), m
********
* *
* *
* *
* *
********
n = 2, m = 3
***
***
line of stars
stars: m
main pattern
star: 1
spaces: m - 2
star: 1
line of stars
stars: m
*/
/*
Time complexity: m + nm + m
2m + nm
m (2 + n)
m * n
O(nm)
*/
public static void main(String[] args) {
// user input
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
// first row
// time Complexity: O(m)
for (int i = 0 ; i < m ; System.out.print('*'), i++);
System.out.println();
// main pattern
// Time complexity: O(n * m)
for (int i = 0 ; i < n - 2 ; i++) {
// Time Complexity: O(m)
// print star
System.out.print('*');
// spaces
for (int j = 0 ; j < m - 2 ; System.out.print('_'), j++);
// star
System.out.println('*');
}
// last row
// time complexity: O(m)
for (int i = 0 ; i < m ; System.out.print('*'), i++);
}
}