[백준] 1264번(Java/자바)

Yeoonnii·2022년 12월 11일
0

백준 1264번 모음의 개수

🧾 구현

  1. 모음의 대소문자로 구성된 index 배열 생성
  2. cnt 변수 초기화
  3. 입력받은 문장의 길이만큼 반복문 실행, charAt로 문자열 문자로 쪼개기
  4. 1의 index 배열 길이만큼 반복문 실행,
    3에서 쪼갠 문자열이 index안의 배열원소와 일치하면 cnt 증가

💻제출 코드

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(true){
            String str = sc.nextLine();

            if(str.equals("#")){
                break;
            }

            char[] index = {'A','E','I','O','U','a','e','i','o','u'};
            int cnt = 0;

            for(int i=0; i<str.length(); i++){
                char c = str.charAt(i);
                for(int j=0; j<index.length; j++){
                    if(c == index[j]){
                        cnt++;
                    }
                }
            }
        System.out.println(cnt);
        }
        sc.close();
            }    
}

0개의 댓글