-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPattern3.java
43 lines (36 loc) Β· 832 Bytes
/
Pattern3.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
package day2;
import java.util.Scanner;
public class Pattern3 {
/*
n = 4
1
12
123
1234
n = 2
1
12
numbers: i + 1
f : 1 2 3 4 ...
j : 0 1 2 3 ...
jth number: j + 1
*/
/*
Time Complexity: O(n^2)
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0 ; i < n ; i++) {
// printing numbers
// i + 1 i [0, n]
// 1 2 3 4 5 ... n
// 1 + 2+ 3 + 4 + 5 + ... + n = n(n + 1) / 2 O(n^2)
for (int j = 0 ; j < i + 1 ; j++) {
System.out.print(j + 1);
}
// new line
System.out.println();
}
}
}