Advertisement
veronikaaa86

06. Vowels Sum

Oct 1st, 2022
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package forLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P06VowelsSum {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String textInput = scanner.nextLine();
  10.  
  11.         int sum = 0;
  12.         for (int i = 0; i < textInput.length(); i++) {
  13.             char symbol = textInput.charAt(i);
  14.  
  15.             switch (symbol) {
  16.                 case 'a':
  17.                     sum = sum + 1; break;
  18.                 case 'e':
  19.                     sum = sum + 2; break;
  20.                 case 'i':
  21.                     sum = sum + 3; break;
  22.                 case 'o':
  23.                     sum = sum + 4; break;
  24.                 case 'u':
  25.                     sum = sum + 5; break;
  26.             }
  27.         }
  28.         System.out.println(sum);
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement