Guest User

Untitled

a guest
Jan 13th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import java.io.*;
  2. public class HumanlyPronounceableCombination extends AllCombination
  3. {
  4. //--------------------------------------------
  5. // Method that check character is vowel or not
  6. //--------------------------------------------
  7. public boolean isvowel(char c)
  8. {
  9. if(c == 'a')
  10. {
  11. return true;
  12. }
  13. else if( c == 'e')
  14. {
  15. return true;
  16. }
  17. else if(c == 'i')
  18. {
  19. return true;
  20. }
  21. else if(c == 'o')
  22. {
  23. return true;
  24. }
  25. else if(c == 'u')
  26. {
  27. return true;
  28. }
  29. else
  30. {
  31. return false;
  32. }
  33. }
  34. //---------------------------------------------------------
  35. // Method that generate Humanly Pronounceable Combination .
  36. //---------------------------------------------------------
  37. public String showHumanlyPronounceableCombination(String stringInput)
  38. {
  39. String wordArray="";
  40. String strbase="";
  41. String output = "";
  42. int flag=1;
  43. stringInput=stringInput.toLowerCase();
  44. String allComb=allCombination(wordArray,strbase,stringInput);
  45. String[] combArray = allComb.split(",");
  46.  
  47. for(int i = 0; i < combArray.length; i++)
  48. {
  49. for(int j = 0; j < combArray[i].length()-1; j++)
  50. {
  51. char [] charArray = combArray[i].toCharArray();//convert combination string to char array
  52. if(!isvowel(charArray[j]))
  53. {
  54. if(isvowel(charArray[j+1]))
  55. {
  56. flag = 0;
  57. }
  58. else
  59. {
  60. flag = 1;
  61. break;
  62. }
  63. }
  64. if(isvowel(charArray[j]))
  65. {
  66. flag = 2;
  67. }
  68. if(flag == 0)
  69. {
  70. if(isvowel(charArray[j+1]))
  71. {
  72. flag = 0;
  73. }
  74. else
  75. {
  76. flag = 1;
  77. break;
  78. }
  79. }
  80. }
  81.  
  82. if(flag == 0 || flag == 2)
  83. {
  84. if(output == "")
  85. {
  86. output = combArray[i];
  87. }
  88. else
  89. {
  90. output = output+","+combArray[i] ;
  91. }
  92. }
  93. }
  94. return output;
  95. }
  96. public static void main(String[] args)throws ArrayIndexOutOfBoundsException, IOException
  97. {
  98. HumanlyPronounceableCombination s = new HumanlyPronounceableCombination();
  99. DataInputStream dis = new DataInputStream(System.in);
  100. System.out.println("Enter String : ");
  101. String inputString = dis.readLine();
  102. String output = s.showHumanlyPronounceableCombination(inputString);
  103. System.out.println("Output String : "+output);
  104.  
  105. }
  106. }
Add Comment
Please, Sign In to add comment