1. Engineering
  2. Computer Science
  3. hi i want to add an extra case in my...

Question: hi i want to add an extra case in my...

Question details

Hi I want to add an extra case in my that count the number of consonants(All the letters excepts for a.) in the sentence. The java code:

import java.util.Scanner;
public class vowels{
public static void main(String[] args){
String sentence;
int index = 0;
int num_vowels =0;
int num_const = 0;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a sentence");
sentence= scan.nextLine();
System.out.println("Sentence is :" + sentence);
//A, E, I, O, and U.
  
while (index < sentence.length()){
switch (sentence.charAt(index))
{
case 'a':
num_vowels++;
break;
case 'e':
num_vowels++;
break;
case 'i':
num_vowels++;
break;
case 'o':
num_vowels++;
break;
case 'u':
num_vowels++;
break;
case != 'a'

}
index++;
}
System.out.println("VowelCount :" + num_vowels);
System.out.println("consonants :" + num_vowels);
  
}
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution