Advertisement
svetlyo0659

Untitled

Feb 19th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class VowelsCount
  4. {
  5.   public static void main(String[] args)
  6.   {
  7.     Scanner in = new Scanner(System.in);
  8.     System.out.println("Please enter a word or a sentence:");
  9.     String line = in.nextLine();
  10.     char letter ;
  11.     int countOfVowels=0;
  12.     for (int i = 0; i <line.length() ; i++) {
  13.       letter = line.toLowerCase().charAt(i);
  14.  
  15.       switch (letter){
  16.         case 'a':
  17.         case 'e':
  18.         case 'i':
  19.         case 'o':
  20.         case 'u':
  21.           countOfVowels++;
  22.           break;
  23.       }
  24.     }
  25.     System.out.println("Count of vowels in this word/sentence is: " + countOfVowels);
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement