desislava_topuzakova

06. Vowels Sum

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