desislava_topuzakova

6. Сумиране на гласните букви

Nov 28th, 2021
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package ForLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SumVowels_06 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String text = scanner.nextLine();
  9.         int sum = 0; //сумата от гласните букви
  10.         for (int position = 0; position <= text.length() - 1; position++) {
  11.             char currentSymbol = text.charAt(position);
  12.             //проверка дали е гласна -> a, e, i, o, u
  13.             switch (currentSymbol) {
  14.                 case 'a':
  15.                     sum += 1; //sum = sum + 1;
  16.                     break;
  17.                 case 'e':
  18.                     sum += 2; //sum = sum + 2;
  19.                     break;
  20.                 case 'i':
  21.                     sum += 3; //sum = sum + 3;
  22.                     break;
  23.                 case 'o':
  24.                     sum += 4; //sum = sum + 4;
  25.                     break;
  26.                 case 'u':
  27.                     sum += 5; //sum = sum + 5;
  28.                     break;
  29.             }
  30.         }
  31.  
  32.         System.out.println(sum);
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment