Power java 07장 Programming 6번문제 풀이

Posted by 알 수 없는 사용자
2016. 3. 30. 15:59 Java/PowerJava 문제풀이

※ 문제풀이는 작성자 본인이 직접 한것이므로 100%정답이 아닐 수 있습니다.

   혹시 보시고 틀린 부분이 있으면 알려주시기 바랍니다.


6. 사용자로부터 받은 문자열에서 자음과 모음 개수를 계산하는 프로그램을 작성하라.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package day04;
 
import java.util.Scanner;
 
class Alpabet{
    String str;
    
    public void input(){
        Scanner sc = new Scanner(System.in);
        System.out.print("문자열 입력 :");
        str = sc.nextLine();
        
    }
    public void alpacount(){
        int vowel=0, consonant=0;
        for(int i=0;i<str.length();i++){
            char c = str.charAt(i);
            switch(c){
            case 'a'case 'e'case 'i'case 'o'case 'u'
            case 'A'case 'E'case 'I'case 'O'case 'U':
                
                vowel++break;
            case ' ':
                break;
            default:
                consonant++break;
            }
        }
        System.out.println("모음의 개수는 :"+vowel+" 자음의 개수는 :"+consonant);
        
    }
}
public class Programming7_6 {
    public static void main(String[] args) {
        Alpabet al = new Alpabet();
        al.input();
        al.alpacount();
        
    }
}
 
cs

※ 문제 출처 : POWER JAVA 2판/인피니티북스/천인국 하상호 공저