Hello, guys.
I'm very new to Java and this is my first time I'm actually programming by myself. I have a homework due soon.
Anyways, my question is:
Write a program that asks the user for a word to replace in some text, and the word to replace it with. The program then reads a line of text from the user and echoes the line back to screen replacing all occurrences of the first word with the second word. It only replaces the word being censored when it occurs independently in a line (i.e. not as a part of another word).
Like:
Enter word to censor: dumb
Enter word to replace it: xxxxx
Enter line of text to censor:
The guy is dumb but his friend is even dumber.
The guys is xxxxx but his friend is even dumber.
import java.util.*;
public class LineCensor
{
public static void main(String args[])
{
String sentence = "Please type a word to Censor:";
Scanner keyboard = new Scanner(System.in);
String = keyboard.nextDouble();
System.out.println(altstring);
String [] temp = null;
temp = sentence.split(" ");
for (int j=0; j < temp.length; j++ )
{
if (temp[j].equals("bridge"))
{
sentence = "Censored";
}
}
System.out.println(sentence + " " + ac);
}
}
Thats all I know. Can someone help me with the code ? How do I replace some word to something ?
I know its not compiling either. I'm kind of stuck as this is my first time with java?