문제 & 예시
소스코드
// 문자열 내 p와 y의 개수
public class test24 {
public static void main(String[] args) {
Solution24 sol = new Solution24();
String s = "pPoooyY";
System.out.println(sol.solution(s));
}
}
class Solution24 {
boolean solution(String s) {
boolean answer = true;
int cnt_p = 0; // p의 갯수
int cnt_y = 0; // y의 갯수
// 소문자로 arr배열에 s문자열을 넣어준다.
String[] arr = s.toLowerCase().split("");
for(int i=0;i<arr.length;i++) {
if(arr[i].equals("p")) {
++cnt_p;
}else if(arr[i].equals("y")) {
++cnt_y;
}
}
// p의 갯수와 y의 갯수가 다르면 fasle
if(cnt_p != cnt_y) {
answer = false;
}
return answer;
}
}