// The "StringReplacement" class.
import java.awt.*;
import hsa.Console;

public class StringReplacement
    static Console c;           // The output console

    public static void main (String[] args)
        c = new Console ();

        String word;
        String word2;
        String sentences;
        int i;

        c.print ("Enter the word to be replaced: ");
        word = c.readLine ();
        c.print ("Enter the word to replace it; ");
        word2 = c.readLine();
        c.print ("Enter the sentence: ");
        sentences = c.readLine ();

        String[] arraystr = sentences.split (" ");

        for (i = 0 ; i < arraystr.length ; i++)
            if (arraystr [i].equals (word))     
            c.print (word2);         
            c.print (arraystr [i] + " ");

    } // main method
} // StringReplacement class

My problem is I need to remove the word at the arraystr and replace it with word2 without using substring(). Anyone can help?

Edited by Daigan: n/a

6 Years
Discussion Span
Last Post by Daigan
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.