백준 #2386번 도비의 영어 공부

jhj·2025년 1월 18일

백준 JAVA

목록 보기
553/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		while(!a.equals("#")) {
			String b = sc.nextLine();
			int count = 0;
			String upper = b.toUpperCase();
			String lower = b.toLowerCase();
			
			for(int i = 0; i < b.length(); i++) {
				if(a.charAt(0) == upper.charAt(i) || a.charAt(0) == lower.charAt(i)) {
					count++;
				}
			}
			System.out.println(a + " " + count);
			a = sc.next();
		}
		sc.close();
	}
}

upper.charAt(i)는 char형이다.
a는 String 형이므로, upper.charAt(i)의 형(char)과 똑같이 변형 시켜 주어야 한다.

profile
개발자를 꿈꾸는

0개의 댓글