Taking vowels from string. Java -


i'm having trouble simple exercise. have take vowels string: astring.

this return vowels string, whant is, if there 3 a, return one.

example:

string astring = "aaa eee iii"; 

the return should be: a e i

this have reached.

    public static void getvowels(char achar, string astring){     system.out.print("your string has following vowels: ");     (int = 0; < astring.length(); i++){         if ((astring.charat(i) == 'a') || (astring.charat(i) == 'e') || (astring.charat(i) == 'i') || (astring.charat(i) == 'o') || (astring.charat(i) == 'u')) {                 achar = astring.charat(i);                 system.out.print(achar + " ");         }     }    } 

thx , sorry bad english.

edit code follows:

public static void getvowels(char achar, string astring) { system.out.print("your string has following vowels: "); string vowels=""; (int = 0; < astring.length(); i++) {     if ((astring.charat(i) == 'a') || (astring.charat(i) == 'e') || (astring.charat(i) == 'i') || (astring.charat(i) == 'o') || (astring.charat(i) == 'u'))      {         if(!vowels.contains(string.valueof(astring.charat(i))))         vowels+=astring.charat(i);     } } for(int i=0;i<vowels.length();i++)     system.out.print(vowels.charat(i)+" "); } 

edit :

alternatively,

public static void getvowels(char achar, string astring){ system.out.print("your string has following vowels: "); char vowels[]={'a','e','e','o','u'}; (char vowel : vowels) {     if(astring.indexof(vowel)>=0)     {         system.out.print(vowel+" ");     } } } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -