Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class test1
- {
- public static void main(String [] args)
- {
- String phrase = JOptionPane.showInputDialog(null, "Please enter word/phrase to be analyzed");
- vowelsConsonants(phrase);
- }
- public static void vowelsConsonants(String input)
- {
- String result = "";
- String vowels = "aeiou";
- String consonants = "bcdfghjklmnpqrstvwxyz";
- String tempInput = input.toLowerCase();
- tempInput = tempInput.replaceAll("[^a-z]","");
- String first = tempInput.substring(0,1);
- String[] inputArray = tempInput.split("");
- boolean conTrue = true;
- boolean vowTrue = true;
- int i, j;
- if(vowels.indexOf(first) != -1)
- {
- i = 1;
- j = 2;
- }
- else
- {
- i = 0;
- j = 1;
- }
- while(conTrue && i < inputArray.length)
- {
- if(consonants.indexOf(inputArray[i]) == -1)
- conTrue = false;
- i +=2;
- }
- if(conTrue)
- {
- while(vowTrue && j < inputArray.length)
- {
- if(vowels.indexOf(inputArray[j]) == -1)
- vowTrue = false;
- j += 2;
- }
- }
- if(vowTrue && conTrue)
- result += "Word/phrase entirely comprises of alternating vowels and consonants";
- else
- result += "Word/phrase does not entirely comprise of alternating vowels and consonants";
- JOptionPane.showMessageDialog(null, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement