Results 1 to 3 of 3
  1. #1
    manda147 is offline Member
    Join Date
    Nov 2008
    Rep Power

    Default replacing characters???

    I'm supposed to write a program that replaces all vowels in a word with * but i can't get it right! the most i can do is replace one vowel with teh code:

    Java Code:
    import java.util.Scanner;
    public class constanita {
    	public static void main (String[]args){
    		Scanner kbd = new Scanner(;
    		System.out.println("enter a word");
    		String x =;;
    		String noVowels = x.replace("a", "*"); 
    and whenever i try something like

    String noVowels = x.replace("a", "*"),replace("e", "*");

    etc etc

    it tells me error

    can anyone help?
    thanks in advance

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    Using replaceFirst(String) and replaceAll(String)

    That gets into regex's which will be complicated for you, but will be needful to do it.

    Probably Pattern pattern = Pattern.compile("aeiou");
    Matcher matcher = pattern.matcher(input string);
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Rep Power

    Default loopty loop...

    Yeah... the following will produce a nastgram:
    Java Code:
    String noVowels = x.replace("a", "*"),replace("e", "*");
    You can't concatenate methods (although it's an interesting idea :-)...
    I would attack it with two nested for loops ... the first for will loop through the string and the second will loop through the string or array of vowels.

    I agree with Nicholas, regex would be a more solid approach but from the display of interesting arrangement of methods, I'm assuming that getting the nested for loops together will be a challenge.

    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. [SOLVED] regexs not finding or replacing
    By Nicholas Jordan in forum Advanced Java
    Replies: 7
    Last Post: 07-30-2008, 10:02 PM
  2. Pls helpme in replacing set and get methods with List
    By shobha2k8 in forum New To Java
    Replies: 1
    Last Post: 07-16-2008, 09:25 AM
  3. replacing array values
    By Jononomous in forum New To Java
    Replies: 1
    Last Post: 05-22-2008, 03:27 PM
  4. Replacing at an index
    By bugger in forum New To Java
    Replies: 2
    Last Post: 01-29-2008, 07:33 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 04:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts