# 자음과 모음(AEIOU) #### CODE <a class='btn btn-default' href='/codes/47808'>Link</a> ``` public class AEIOU { public static void main(String[] args) { // 변수 생성 String s = "Programming is fun! right?"; // 자음 모음 개수 세기 int[] result = count(s); // 결과 출력 System.out.printf("%s\n=> 자음 %d개, 모음 %d개", s, result[0], result[1]); } public static int[] count(String str) { int conso = 0; // 자음 int vowel = 0; // 모음 // 문자열을 문자의 배열로 만듬 // {'P','r','o','g','r','a','m','m','i','n','g','i','s','f','u','n','!','r','i','g','h','t','?'} char[] characters = str.toCharArray(); // 모든 문자 배열을 순회하며 검사 for (int i = 0; i < characters.length; i++) { switch (characters[i]) { // 모음 case 'A': case 'E': case 'I': case 'O': case 'a': case 'e': case 'i': case 'o': case 'u': vowel++; break; // 공백 및 특수 문자 제외 case ' ': // 스페이스 case '\t': // 탭 case '\n': // 엔터 case ',': // 콤마 case '.': // 닷 case '!': case'?': break; // 그 외(자음) default: conso++; break; } } **return new int[] { conso, vowel };** // count라는 메소드의 retrun값이 int라는 정수형 배열인 건 알겠는데 배열 그 자체가 반환되는게 아닌 배열의 값? 변수? ... { }이런 형태로도 반환될 수 있는건가요? 보통 배열을 선언할 때 자료형[] 배열명 = {값1, 값2, 값2, ...} 또는 자료형[] 배열명 = new 자료형[] 이런식으로 했던 것 같은데 여기서는 처음 보는 방식으로 서술이 되어있어서요.. 그리고 문제에서 구한 모음 자음 결과를 출력할 때 // 자음 모음 개수 세기 int[] result = count(s); 이 과정을 통해 result[0] = conso, result[1] = vowel로 들어가서 // 결과 출력 System.out.printf("%s\n=> 자음 %d개, 모음 %d개", s, result[0], result[1]); 결과출력이 되는것 같은데 이렇게 conso와 vowel이 result라는 함수의 요소가 되어서 result[0], result[1]로 치환되는게 이해가 잘 안갑니다.. } } ``` #### INPUT ``` ``` #### OUPUT ``` Programming is fun! right? => 자음 15개, 모음 6개 ```
# 배열 객체의 생성 배열은 다양한 방법으로 생성할 수 있습니다. 다음의 세번째 방법이, 질문 내용에 적용된 코드 되겠습니다. ``` int[] a = { 1, 2, 3 }; int[] b = new int[3]; int[] c = new int[] { 1, 2, 3 }; ```