글
프로그래머스 문자열 내의 p와 y의 개수(JAVA, toLowerCase().split(""), equals)
프로그래밍
2023. 2. 11. 13:34
728x90
SMALL
class Solution {
boolean solution(String s) {
int pCount = 0, yCount = 0;
String[] array = s.toLowerCase().split(""); //소문자로 바꾸고 잘라 배열에 넣음
for (int i = 0; i < array.length; i++)
{
if ("p".equals(array[i]))
{
pCount++;
}
else if ("y".equals(array[i]))
{
yCount++;
}
}
if (pCount != yCount)
{
return false;
}
return true;
}
}
728x90
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 행렬의 곱셈(3중 for문, JAVA) (0) | 2023.02.11 |
---|---|
프로그래머스 C# 예상 대진표(JAVA) (0) | 2023.02.11 |
프로그래머스 JAVA 폰켓몬 (0) | 2023.02.09 |
프로그래머스 레벨0 안전지대(C#, JAVA) try catch(Exception e) (0) | 2023.02.09 |
다항식 더하기 JAVA (0) | 2023.02.09 |