Results 1 to 7 of 7
  1. #1
    bakemono44 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default I need help for my Java Assigment , replacing string

    Hi , I have a assigment that was already due but I still want to work on it.
    For this program im trying to replace every 4 words with with 4 astericks . It is suppose to be read from a file
    and the line cannot exceed more than 80 characters.
    So this what I have so far...

    I'm also not allowed to use java codes that are off my level because I am new at this.

    Java Code:
    /**
     * 
     */
    package replace;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Scanner;
     
    public class replace {
     
     
    	public static void main(String[] args) throws IOException {
     
    		File file = new File ("input.txt");
     
    		Scanner inputFile= new Scanner(file);
     
    		String input;
    		String line;
    		int StringLength;
     
    		line=inputFile.nextLine(); //read first line
     
    	for(int x=0;x<line;x++){
    		line=inputFile.nextLine();//read line
    		StringLength=line.length(); //get length of string
    		int y;
    		while( y<StringLength){
     
    			if (input.charAt(y)isWhiteSpace); //save the characters before whitespace
     
    			System.out.println(y);
    		}
     
     
    	}
     
     
     
     
     
    	}
     
    	}
     
    }

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: I need help for my Java Assigment , replacing string

    what exactly are the errors you are getting. or what is the output you receive?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help for my Java Assigment , replacing string

    What is your question? Where exactly are you stuck?

  4. #4
    bakemono44 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: I need help for my Java Assigment , replacing string

    Quote Originally Posted by Fubarable View Post
    What is your question? Where exactly are you stuck?

    I don't know what to do afterwards and I also get a error at line 23 and 31. I don't know how to make it replace a four letter string with four astericks

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help for my Java Assigment , replacing string

    If you get an error, you should post the complete error message.

    If you can, show some of the data file and the exact output expected.

  6. #6
    bakemono44 is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: I need help for my Java Assigment , replacing string

    I can't really show the error message because my program isn't complete..
    But this how I would like it to be:
    Input: Hi my name is Todd
    Output: Hi my **** is ****

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help for my Java Assigment , replacing string

    Quote Originally Posted by bakemono44 View Post
    I can't really show the error message because my program isn't complete.
    Well, if you need help with the errors, you'll need to show them, and indicate what code is causing them.

    But this how I would like it to be:
    Input: Hi my name is Todd
    Output: Hi my **** is ****
    So, your goal is to replace any four-character words with astericks. That's different then what you've described above.

    As with any programming assignment or task, you shouldn't try to solve it all at once, but instead the key is in breaking down the project into smaller steps and then trying to solve each small step one at a time. I suggest that you do this now, and then let us know which step exactly stumps you.

Similar Threads

  1. Replacing Image for a String
    By vimalaranjan in forum Java 2D
    Replies: 6
    Last Post: 05-04-2011, 06:09 PM
  2. Replacing char in string help
    By jimmy-lin in forum New To Java
    Replies: 3
    Last Post: 10-12-2009, 06:01 AM
  3. Replacing the chars within a string.
    By Mayur in forum New To Java
    Replies: 2
    Last Post: 03-27-2009, 04:00 AM
  4. Help Replacing String
    By 7oclock in forum New To Java
    Replies: 5
    Last Post: 02-14-2009, 07:31 AM
  5. Help with variable assigment to String
    By silvia in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:43 AM

Posting Permissions

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