본문 바로가기

프로그래머스

프로그래머스 - 문자열 다루기 기본

class Solution {
public boolean solution(String s) {
boolean answer = true;

char c;
int cToI;

if (s.length() == 4 || s.length() == 6) {
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
cToI = (int) c;

if (cToI < 48 || cToI > 57) {
answer = false;
break;
}
}
} else {
answer = false;
}
return answer;
}
}