강의

멘토링

로드맵

Inflearn Community Q&A

bgan06041911's profile image
bgan06041911

asked

Introduction to Java Algorithm Problem Solving: Coding Test Preparation

1. Find a Character

이거는 왜 오답인가요? 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); 이어야 한다고 생각합니다

gulang님의 프로필 이미지
gulang
Questioner

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

0

입력 문자열은 대문자로 변환하는 반면 입력 문자는 대문자로 변환하지 않는 부분도 확인해 보면 좋을 것 같습니다.

bgan06041911's profile image
bgan06041911

asked

Ask a question