Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: I need help for my Java Assigment , replacing string

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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 an 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.

    /**
     * 
     */
    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
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

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

    Can you explain what the problem is? If you are getting errors, copy the full text and paste it here.
    If the output is wrong, copy and paste here the output and explain what is wrong with it and show what the output should be.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replacing parts of a String using line.replaceAll
    By brandonSMC in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 27th, 2012, 05:07 PM
  2. new to java, and need help with assigment
    By knotski in forum What's Wrong With My Code?
    Replies: 22
    Last Post: March 30th, 2012, 02:48 PM
  3. Need help with java assigment
    By Lutzor in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 3rd, 2011, 06:29 PM
  4. [SOLVED] Replacing letters in a string NOT WORKING.
    By sp11k3t3ht3rd in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 14th, 2011, 06:38 PM
  5. [SOLVED] replacing elements in a string
    By sp11k3t3ht3rd in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2011, 07:31 PM