프로그래머스 코딩테스트연습
연습문제 문자열 내 p와 y의 개수
난이도 Level1
https://programmers.co.kr/learn/courses/30/lessons/12916
class Solution {
boolean solution(String s) {
boolean answer = true;
int countP = 0;
int countY = 0;
s = s.toUpperCase();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'P') {
countP++;
} else if (s.charAt(i) == 'Y') {
countY++;
}
}
if (countP == countY) {
answer = true;
} else if (countP != countY) {
answer = false;
}
return answer;
}
}
Java 문자열(String) 함수가 헷갈리는게 있어서 다시 정리해서 포스팅해보면서 공부하자.