Advertisement
desislava_topuzakova

06. Vowels Sum

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