-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel_3.java
More file actions
49 lines (37 loc) · 1.07 KB
/
Level_3.java
File metadata and controls
49 lines (37 loc) · 1.07 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
package org.programmers;
import java.util.Arrays;
import java.util.ArrayList;
public class Level_3 {
public static void main(String[] args) {
System.out.println(solution(6));
System.out.println(solution(7));
System.out.println(solution(8));
System.out.println(solution(9));
}
//-- 해당 숫자가 124에 해당하는지 확인한다.
public static int is_124(int num) {
int x,y;
do {
x = num % 10;
if ( x != 1 && x !=2 && x !=4) {
return -1;
}
num = num / 10;
} while (num > 0);
return 1;
}
public static String solution(int n) {
String answer = "";
int num = 1;
ArrayList<Integer> allowedNums = new ArrayList<>();
while (allowedNums.size() != n) {
if (is_124(num) == 1) {
allowedNums.add(num);
}
num++;
if (num > 100) break;
}
answer = Integer.toString(allowedNums.get(n-1));
return answer;
}
}