Advertisement
heysoul_sisypus

Vowel consonant counter

Dec 8th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package javaapplication98;
  2. import java.util.*;
  3. /**
  4.  *
  5.  * @author Student
  6.  */
  7. public class JavaApplication98 {
  8.  
  9.     /**
  10.      * @param args the command line arguments
  11.      */
  12.     public static void main(String[] args) {
  13.     Scanner scan=new Scanner (System.in);
  14.     System.out.print("Enter Word: ");
  15.     String line = scan.nextLine();
  16.     int vowels = 0, consonants = 0, digits = 0, spaces = 0;
  17.     line = line.toLowerCase();
  18.     for(int i = 0; i < line.length(); ++i){
  19.             char ch = line.charAt(i);
  20.             if(ch == 'a' || ch == 'e' || ch == 'i'
  21.                 || ch == 'o' || ch == 'u') {
  22.                 ++vowels;
  23.             }
  24.             else if((ch >= 'a'&& ch <= 'z')) {
  25.                 ++consonants;
  26.             }
  27.         }
  28.         System.out.println("Vowels: " + vowels);
  29.         System.out.println("Consonants: " + consonants);
  30.     }
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement