class Solution {
public int solution(int order) {
int answer = 0;
return answer;
}
}
해결법
방법 1
class Solution {
public int solution(int order) {
int answer = 0;
String str = Integer.toString(order);
String[] strArr = str.split("");
int count = 0;
for (int i = 0; i < strArr.length; i++) {
if (strArr[i].equals("3") || strArr[i].equals("6") || strArr[i].equals("9")) {
count++;
}
}
answer = count;
return answer;
}
}
방법 2
class Solution {
public int solution(int order) {
int answer = 0;
int count = 0;
while(order != 0) {
if (order % 10 == 3 || order % 10 == 6 || order % 10 == 9) {
count++;
}
order = order/10;
}
answer = count;
return answer;
}
}
- 일의 자리부터 나눠서, 나머지를 이용하는 방법
방법 3
class Solution {
public int solution(int order) {
int answer = 0;
String str = order + "";
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == '3' || c == '6' || c == '9') {
answer++;
}
}
return answer;
}
}
369게임 Lv. 0