0

doing a lab for class ( cannot use ARRAY )** its a langue converter and i have to put 'ub' after every vowel i was wondering how i could do this WITHOUT AN ARRAY so far i have but it just adds "ub" after the second letter in a string

private static String toUbbi(String word ) {            
    String set = " ";
    if (Vowel (word)){
        set=  word.substring(0)+ "ub"+word.substring(1) ;
        set = word.substring(0,1)+ "ub"+word.substring(1);
    }
    return set;         
}     

private static boolean Vowel(String word ) {             
String[] vowels ={ "a", "e", "i", "o", "u", "ue"} ; 
    //char x = word.charAt(0);
    return (vowels.length !=-1);     
} 
5
  • What I would do is basically use a "target" String into which you can append the changes, substring each prefix section (up to the next vowel). This gets added to the "target" and "ub". Remove this prefix from the original String and continue until the original String is 0 in length and/or no vowles remain. Assign the target to the original and return... Commented Nov 22, 2013 at 5:29
  • wow thanks for telling be things i already know my problem is syn-text not what i need to do. i dont know how to write any of that Commented Nov 22, 2013 at 5:33
  • Good, now apply it ;) Commented Nov 22, 2013 at 5:44
  • i just said i dont know how to right it Commented Nov 22, 2013 at 5:46
  • Well excuse me for trying to help, in future I won't waste your time Commented Nov 22, 2013 at 5:49

2 Answers 2

1
String word = "test";
String[] vowels ={ "a", "e", "i", "o", "u"}
for (int i = (vowels.length - 1); i>=0; i-- ){

    word = word.replaceAll(vowel[i], vowel[i].concat("ub"));
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can try this:

public static void main(String[] args)
{
    String str = "christian";
    String new_str = "";

    for (int i = 0; i < str.length(); i++) {
        new_str += str.charAt(i);
        if (isVowel(str.charAt(i))) // If is a vowel
            new_str += "ub";
    }
    System.out.println(new_str);
}

private static boolean isVowel(char c)
{
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
        return true;
    return false;
}

1 Comment

StringBuilder please!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.