import java.util.*;
class Main {
// solution 메서드 정의, str과 t를 매개변수로 받음
public int solution(String str, char t) {
int count = 0;
// 문자열 str을 대문자로 변환
str = str.toUpperCase();
// 입력된 문자 t를 대문자로 변환
t = Character.toUpperCase(t);
for(int i = 0; i < str.length(); i++) {
// t와 문자열 str을 1글자씩 비교하고 참이면 count에 1 더하기
if(t == str.charAt(i))
count++;
}
return count;
}
public static void main(String []args) {
// Main 클래스의 인스턴스 T 생성, 이걸 통해 solution 호출 가능
Main T = new Main();
// Scanner 생성
Scanner kb = new Scanner(System.in);
// str에 입력한 문자열 저장
String str = kb.next();
// 입력한 단어의 첫 문자를 c에 저장
char c = kb.next().charAt(0);
// T를 통하여 solution을 호출하고 str과 c를 인자로 전달
// 그 결과를 System.out.println을 통해 출력
System.out.println(T.solution(str, c));
}
}
import java.util.*;
class Main {
public int solution(String str, char t) {
int count = 0;
str = str.toUpperCase();
t = Character.toUpperCase(t);
for(int i = 0; i < str.length(); i++) {
if(t == str.charAt(i))
count++;
}
return count;
}
public static void main(String []args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
String str = kb.next();
char c = kb.next().charAt(0);
System.out.println(T.solution(str, c));
}
}
'코딩테스트 > 기초' 카테고리의 다른 글
6. 중복문자제거 (0) | 2024.12.02 |
---|---|
5. 특정 문자 뒤집기 (0) | 2024.12.01 |
4. 단어 뒤집기 (0) | 2024.12.01 |
3. 문장 속 단어 (0) | 2024.11.30 |
2. 대소문자 변환 (1) | 2024.11.28 |