Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class alphabetType{
- public static void main(String args[]){
- int consonants=0, vowels=0,others = 0;
- System.out.print("Enter a String: ");
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- input = input.toLowerCase();
- for(int i = 0; i < input.length(); i++){
- switch(input.charAt(i)){
- case 'a': case'e':case 'i': case'o':
- case 'u': vowels++; break;
- case'b':case'c':case'd':case'f':
- case'g':case'h':case'j':case'k':
- case'l':case'm':case'n':case'p':
- case'q':case'r':case's':case't':
- case'v':case'w':case'x':case'y':
- case'z': consonants++; break;
- default: others++;
- }
- }
- System.out.println(consonants+" consonants & "+vowels+" vowels present. "+others+" other characters present.");
- }
- }
- //Output:-
- //C:\Java>java alphabetType
- //Enter a String: Thanks for visiting my Pastebin!
- //19 consonants & 8 vowels present. 5 other characters present.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement