Advertisement
desislava_topuzakova

06. Vowels Sum

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