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

    Default replacing characters???

    Hi,
    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.in);
    		
    		System.out.println("enter a word");
    		
    		String x = kbd.next();;
    
    		
    		String noVowels = x.replace("a", "*"); 
    
    		
    		
    		System.out.println(noVowels);
    		
    		
    	}
    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
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    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
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    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 :-)...
    Anyway...
    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.

    Luck,
    CJSL
    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, 06:33 AM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 03: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
  •