Text Item Series [2]--string vowel count

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.