Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class HumanlyPronounceableCombination extends AllCombination
- {
- //--------------------------------------------
- // Method that check character is vowel or not
- //--------------------------------------------
- public boolean isvowel(char c)
- {
- if(c == 'a')
- {
- return true;
- }
- else if( c == 'e')
- {
- return true;
- }
- else if(c == 'i')
- {
- return true;
- }
- else if(c == 'o')
- {
- return true;
- }
- else if(c == 'u')
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- //---------------------------------------------------------
- // Method that generate Humanly Pronounceable Combination .
- //---------------------------------------------------------
- public String showHumanlyPronounceableCombination(String stringInput)
- {
- String wordArray="";
- String strbase="";
- String output = "";
- int flag=1;
- stringInput=stringInput.toLowerCase();
- String allComb=allCombination(wordArray,strbase,stringInput);
- String[] combArray = allComb.split(",");
- for(int i = 0; i < combArray.length; i++)
- {
- for(int j = 0; j < combArray[i].length()-1; j++)
- {
- char [] charArray = combArray[i].toCharArray();//convert combination string to char array
- if(!isvowel(charArray[j]))
- {
- if(isvowel(charArray[j+1]))
- {
- flag = 0;
- }
- else
- {
- flag = 1;
- break;
- }
- }
- if(isvowel(charArray[j]))
- {
- flag = 2;
- }
- if(flag == 0)
- {
- if(isvowel(charArray[j+1]))
- {
- flag = 0;
- }
- else
- {
- flag = 1;
- break;
- }
- }
- }
- if(flag == 0 || flag == 2)
- {
- if(output == "")
- {
- output = combArray[i];
- }
- else
- {
- output = output+","+combArray[i] ;
- }
- }
- }
- return output;
- }
- public static void main(String[] args)throws ArrayIndexOutOfBoundsException, IOException
- {
- HumanlyPronounceableCombination s = new HumanlyPronounceableCombination();
- DataInputStream dis = new DataInputStream(System.in);
- System.out.println("Enter String : ");
- String inputString = dis.readLine();
- String output = s.showHumanlyPronounceableCombination(inputString);
- System.out.println("Output String : "+output);
- }
- }
Add Comment
Please, Sign In to add comment