RGAlex

O2. Vowels Count

Feb 5th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package ExerciseMethoods;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class O2VowelsCount {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String command = scanner.nextLine();
  9.         System.out.println(number(command));
  10.     }
  11.  
  12.     private static int number(String command) {
  13.         int sum = 0;
  14.         for (int i = 0; i < command.length(); i++) {
  15.  
  16.             char currentChar = command.charAt(i);
  17.             switch (currentChar) {
  18.                 case 'a':
  19.                 case 'e':
  20.                 case 'i':
  21.                 case 'o':
  22.                 case 'u':
  23.                 case 'A':
  24.                 case 'E':
  25.                 case 'I':
  26.                 case 'O':
  27.                 case 'U':
  28.                     sum += 1;
  29.                     break;
  30.                 default:
  31.                     break;
  32.             }
  33.         }
  34.         return (sum);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment