[Programmers] 문자열 다루기 기본 - 연습문제

동민·2021년 3월 10일
// 문자열 다루기 기본 - 연습문제
public class StringPrimary {

	public boolean solution(String s) {

		if (s.length() == 4 || s.length() == 6) {

			for (int i = 0; i < s.length(); i++) {
				if ((s.charAt(i) >= 'a' && s.charAt(i) <= 'z')) {
					return false;
				}
			}
		} else {
			return false;
		}
		return true;
	}

	public static void main(String[] args) {

		StringPrimary s = new StringPrimary();
		System.out.println(s.solution("a234")); // false
		System.out.println(s.solution("1234")); // true
		System.out.println(s.solution("1a34")); // false
		System.out.println(s.solution("d132as")); // false
		System.out.println(s.solution("11331")); // false

	}

}
profile
BE Developer

0개의 댓글