Advertisement
Guest User

Vowels

a guest
Feb 19th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Vowels
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner in = new Scanner(System.in);
  8. System.out.println("Please enter a sentence:");
  9. String sentence = in.nextLine(); //user inpt
  10. // vowels a, e, i, o, u, y
  11.  
  12. int sentenceLenght = sentence.length();
  13. int vowelsCount = 0;
  14.  
  15. for (int i = 0; i < sentenceLenght; i++) {
  16. char character = sentence.charAt(i);
  17. switch (character) {
  18. case 'a':
  19. case 'e':
  20. case 'i':
  21. case 'o':
  22. case 'u':
  23. case 'y':
  24. vowelsCount++;
  25. break;
  26. }
  27. }
  28.  
  29. if (vowelsCount > 0) {
  30. System.out.println("Number of vowels: " + vowelsCount);
  31. } else {
  32. System.out.println("There are no vowels in the sentence!");
  33. }
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement