PROGRAMMERS/연습문제

PROGRAMMERES Level 1 연습문제 문자열 내 p와 y의 개수 (JAVA 자바)

c0mmedes 2022. 8. 23. 16:57
import java.util.*;

class Solution {
    boolean solution(String s) {
        boolean answer = true;
        int pcount=0;
        int ycount=0;
        
        s = s.toLowerCase();
        
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i)=='p') pcount++;
            if(s.charAt(i)=='y') ycount++;
        }
        
        if(pcount == ycount) {
            return answer;
        } else{
            answer = false;
            return answer;
        }
        
    }
}
댓글수0