Vowel Consonants Count Using Java

Only available on StudyMode
  • Topic: Vowel, Perl
  • Pages : 3 (277 words )
  • Download(s) : 853
  • Published : September 11, 2011
Open Document
Text Preview
package vowelCons;

import java.util.Scanner;

public class VowelCons {

public static void main(String args[]){

String input;
char selection;
int x = 0;
char[] a = new char[100];

Scanner keyboard = new Scanner(System.in);

System.out.print("Enter a string: ");
input = keyboard.nextLine();

x = input.length();

//Convert from String to Char

for (int p = 0; p < x; p++) { a[p] = input.charAt(p); // in these couple lines here. }

// Determine amount of Vowels and Cons
int Vowels = 0;
int Cons = 0;

for (int i = 0; i < 100 ; i++){
if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u'){ Vowels++;
}else{
Cons++;
}
}

// Switch case to determine which Menu was Selected and Print corresponding Results
do{
selection = getMenuSelection();

switch(Character.toLowerCase(selection))
{
case 'a' : System.out.println("\nNumber of vowels: " + Vowels); break;
case 'b' : System.out.println("\nNumber of Consonats: " + Cons); break;
case 'c' : System.out.println("\nNumber of vowels: " + Vowels); System.out.println("\nNumber of Consonants: " + Cons); break;
case 'd': System.out.print("Enter a String: ");
input = keyboard.nextLine();
break;
}
} while (Character.toLowerCase(selection)!='e');

}

public static char getMenuSelection() {
String input;
char selection;...
tracking img