Programing
01. [Java] 입력받은 영문자열 모음,자음 개수 판별
p3ngdump
2017. 9. 29. 00:16
영문자열을 사용자에게 입력받아서 모음의 개수와 자음의 개수를 판별해서 출력해주는 프로그램.
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 | package lecture; import java.util.*; class Strstr{ String con_vow = null; int i = 0; int conson, vowel = 0; void consonant() { while(true) { if(con_vow.charAt(i) == 'a' || con_vow.charAt(i) == 'e' || con_vow.charAt(i) == 'i' || con_vow.charAt(i) == 'o' || con_vow.charAt(i) == 'u'){ conson += 1; i++; } else{ vowel += 1; i++; } if(i == con_vow.length()) break; } System.out.println("모음의 개수는 "+conson+"개입니다."); System.out.println("자음의 개수는 "+vowel+"개입니다."); } } public class year { public static void main(String args[]) { Strstr Str_input = new Strstr(); Scanner scan = new Scanner(System.in); System.out.print("문자열 입력: "); Str_input.con_vow = scan.nextLine(); Str_input.consonant(); } } | cs |
반응형