프로그래머스 문자열 P와Y의개수

HyunHwa Cho·2022년 7월 14일
0
package Programmers;

public class PY의개수 {
    public static void main(String[] args) {
        String s = "PpooyY";

        System.out.println(solution(s));
    }


    static boolean solution(String s) {
        int pCount = 0 ;
        int yCount = 0 ;
        String result = s.toUpperCase();
        for(int i = 0; i<result.length(); i++) {
            if (result.charAt(i) == 'P') {
                pCount++;
            }
        }
        for(int i = 0; i<result.length(); i++){
            if (result.charAt(i) == 'Y'){
                yCount++;
            }
        }
        if (pCount == yCount){
            return true;
        } else return false;
    }
}
profile
개발 공부 및 기록용 블로그 입니다.

0개의 댓글