Java
프로그래머스: 문자열 내 p와 y의 개수
Daeryuk Kim
2024. 3. 2. 18:45
import java.util.*;
class Solution {
boolean solution(String s) {
int countP = 0, countY = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == 'p' || c == 'P') countP++;
if (c == 'y' || c == 'Y') countY++;
}
return countP == countY;
}
public static void main(String[] args) {
String s = "pPoooyY";
Solution sol = new Solution();
boolean result = sol.solution(s);
System.out.print(result); // true
}
}