Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class vowels {
  4.  
  5. public static void main(String[] args) {
  6. String input;
  7. int characters;
  8. int a = 0;
  9. int e = 0;
  10. int i = 0;
  11. int o = 0;
  12. int u = 0;
  13.  
  14. JOptionPane.showMessageDialog(null,"This Program asks the user for a sentence, searches for all vowels, and displays the number of times each vowel appears in the sentence.","VOWELS PROJECT", JOptionPane.INFORMATION_MESSAGE);
  15.  
  16. input = JOptionPane.showInputDialog("\n\nEnter the sentence to search:\n");
  17.  
  18. characters = input.length();
  19. String input2 = input.toLowerCase();
  20.  
  21. for(i = 0;i < input2.length(); i++) {
  22. char test = input2.charAt(i);
  23. if(test == 'a') {
  24. a++;
  25. }
  26. else if(test == 'e') {
  27. e++;
  28. }
  29. else if(test == 'i') {
  30. i++;
  31. }
  32. else if(test == 'o') {
  33. o++;
  34. }
  35. else if(test == 'u') {
  36. u++;
  37. }
  38.  
  39. }
  40.  
  41. JOptionPane.showMessageDialog(null,input +" has " + characters + " characters\n" + "There are " +a+" a's, "+e+" e's, "+i+" i's, "+o+" o's, and "+u+" u's.","Output", JOptionPane.INFORMATION_MESSAGE);
  42.  
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement