1

How to get output, if I want to count each vowels character in lowercase and uppercase. The output must print the following lines, inserting the number of appearances of vowel in lowercase and uppercase and the total appearances.

A:_lowercase,_uppercase, _total
E:_lowercase,_uppercase, _total
I:_lowercase,_uppercase, _total
O:_lowercase,_uppercase, _total
U:_lowercase,_uppercase, _total

Here is my code:

import java.util.Scanner;

public class vowelcnt {
    public static void main(String args[]){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Give a string ");
        String input=keyboard.nextLine();
        char []chars=input.toCharArray();
        int upperCase = 0;
        int lowerCase = 0;
        int vowelcount=0;
        for(char c : chars) {
            switch(c){
               case 'a':
               case 'e':
               case 'i':
               case 'o':
               case 'u':
                  vowelcount++;
                  lowerCase++;
                  break;
               case 'A':
               case 'E':
               case 'I':
               case 'O':
               case 'U':
                  vowelcount++;
                  upperCase++;
                  break;
           }  

        }

        System.out.printf("A: %d Lowercase, %d Uppercase,",lowerCase,upperCase,vowelcount);
        System.out.printf("%d Total",vowelcount);

    }
}
user3386109
  • 34,287
  • 7
  • 49
  • 68
B.Nishan
  • 19
  • 2
  • 5
  • https://stackoverflow.com/questions/19661199/how-to-count-vowels-and-consonants-and-capitalizing-first-letter-in-a-string-whi – Maddy Feb 08 '18 at 19:09
  • I don't believe this is a duplicate. This tries to count the number of uppercase, lowercase and total of each vowel separately. – Juan Carlos Mendoza Feb 08 '18 at 19:44
  • You need a separate `lowerCase` and `upperCase` counts for each vowel. That could be done with 10 `int` variables, or an array, or a dictionary where the keys are the vowels and the values are the counts. And you don't need a variable for the total, the total is just `lowerCase + upperCase`. – user3386109 Feb 08 '18 at 20:41

0 Answers0