0

Get the random characters and print only the vowels in java.

is it possible to get only vowels from the randomly generated characters in java? Help me with that please.

29th Jul 2017, 5:38 PM
Bilal Saeed
Bilal Saeed - avatar
1 Resposta
0
A randomly generated String, you mean ? If yes: String getVowels(str) { char[] vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; String output = ""; for(int i = 0; i < str.length; i++) { for(int j = 0; j < vowels.length; j++) { if(str.charAt(i) == vowels[j]) { output += str.charAt(i); break; } } } return output; }
30th Jul 2017, 7:56 AM
Volts
Volts - avatar