Advertisement
myrdok123

06. Vowels Sum

Mar 30th, 2024
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 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  input = scanner.nextLine();
  10.  
  11.         int sum = 0;
  12.  
  13.         //буква        a   e   i   o   u
  14.         //стойност  1   2   3   4   5
  15.  
  16.         for (int i = 0; i < input.length(); i++) {
  17.  
  18.             char currentSymbol = input.charAt(i);
  19.  
  20.             switch (currentSymbol){
  21.  
  22.                 case 'a':
  23.                     sum += 1; // sum = sum + 1
  24.                     break;
  25.                 case 'e':
  26.                     sum += 2;
  27.                     break;
  28.                 case 'i':
  29.                     sum += 3;
  30.                     break;
  31.                 case 'o':
  32.                     sum += 4;
  33.                     break;
  34.                 case 'u':
  35.                     sum += 5;
  36.                     break;
  37.             }
  38.         }
  39.  
  40.         System.out.println(sum);
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement