Advertisement
ruthiek

Untitled

Feb 7th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class test1
  3. {
  4. public static void main(String [] args)
  5. {
  6. String phrase = JOptionPane.showInputDialog(null, "Please enter word/phrase to be analyzed");
  7. vowelsConsonants(phrase);
  8. }
  9. public static void vowelsConsonants(String input)
  10. {
  11. String result = "";
  12. String vowels = "aeiou";
  13. String consonants = "bcdfghjklmnpqrstvwxyz";
  14. String tempInput = input.toLowerCase();
  15. tempInput = tempInput.replaceAll("[^a-z]","");
  16. String first = tempInput.substring(0,1);
  17. String[] inputArray = tempInput.split("");
  18. boolean conTrue = true;
  19. boolean vowTrue = true;
  20. int i, j;
  21. if(vowels.indexOf(first) != -1)
  22. {
  23. i = 1;
  24. j = 2;
  25. }
  26. else
  27. {
  28. i = 0;
  29. j = 1;
  30. }
  31. while(conTrue && i < inputArray.length)
  32. {
  33. if(consonants.indexOf(inputArray[i]) == -1)
  34. conTrue = false;
  35. i +=2;
  36. }
  37.  
  38. if(conTrue)
  39. {
  40. while(vowTrue && j < inputArray.length)
  41. {
  42. if(vowels.indexOf(inputArray[j]) == -1)
  43. vowTrue = false;
  44. j += 2;
  45. }
  46.  
  47.  
  48.  
  49. }
  50. if(vowTrue && conTrue)
  51. result += "Word/phrase entirely comprises of alternating vowels and consonants";
  52. else
  53. result += "Word/phrase does not entirely comprise of alternating vowels and consonants";
  54.  
  55. JOptionPane.showMessageDialog(null, result);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement