1. Requirements
Statistical vowel--enter a string that counts the number of vowels in the office. More complex points, the number of each vowel letter is counted.
2. Ideas
Input: A string of no more than 100 characters. For example: "Love Me Love My Dog".
Processing: The vowel letter is a/e/i/o/u Five, can be counted separately the quantity, the total sum can be.
The output is as follows:
Total number of vowels: 6
A number of times: 0
E Number: 3
I number of times: 0
o Number of times: 3
U Number: 0
3. Code
PackageCom.myeclipse; Public classVowelcount {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubString str = "Love Me Love My Dog"; int[] counts =Getvowelcount (str); System.out.println ("Total number of vowels:" +counts[0]); System.out.println ("A number of times:" +counts[1]); System.out.println ("E-times:" +counts[2]); System.out.println ("I Times:" +counts[3]); System.out.println ("O Times:" +counts[4]); System.out.println ("U number:" +counts[5]); } /*** Count Vowel occurrences *@paramStr No more than 100 characters *@return */ Public Static int[] Getvowelcount (String str) {//creates an array that stores the total number of vowels and the number of occurrences of a/e/i/o/u, respectively . int[] Vowecount =New int[6]; for(inti=0; I<str.length (); i++) { CharTMP =Str.charat (i); Switch(TMP) { Case' A ': vowecount[1]++;Continue; Case' E ': vowecount[2]++;Continue; Case' I ': vowecount[3]++;Continue; Case' O ': vowecount[4]++;Continue; Case' U ': vowecount[5]++;Continue; } } for(intI=1; i<vowecount.length; i++) {vowecount[0] + =Vowecount[i]; } returnVowecount; }}
count the number of vowel letters4. Summary
(1) The condition of switch can also be a char type. Of course, it can also be a byte,short,int type.
(2) after each judgment to continue the cycle, so should use continue, and can not use break.
Text Item Series [2]--string vowel count