Inflearn Community Q&A
이거는 왜 오답인가요? 1-1;
Written on
·
662
·
Edited
0
import java.util.Scanner;
public class Main1_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next().toUpperCase();
char c = str.charAt(0);
System.out.println(c);
int answer = 0;
for(int i=0; i <str.length(); i++) {
if( str.charAt(i) == c) {
answer++;
}
}
System.out.println(answer);
}
}테스트는 잘되는데 왜오답인지모르겠습니다
java코테 준비 같이 해요!
Quiz
61% of people got it wrong. Give it a try!
What is the most efficient way to count the total number of specific characters in a string, ignoring case?
Iterate through the string and compare each character to both the uppercase and lowercase of the target character.
Convert the entire string to a single case (e.g., all uppercase) and count the characters.
Count uppercase and lowercase letters respectively and sum them.
Using a Set data structure, store characters without duplicates and then count them.
Answer 2
1
출력은 하나만 나와야 합니다
또한 char c = str.charAt(0); 이 아닌 char c = sc.next().charAt(0); 이어야 한다고 생각합니다
0






아 제가 문제를 잘못읽었네요 단어의 첫번째알파벳이아니라 주어진 알파벳이었군요. 테스트케이스 보는법을 몰라서 왜틀렸는지몰랐는데 테케보는법을 찾아서 알게되었습니다. 답변감사합니다!