I need help with a assignment im doing....i would really appreciate it

im new to java programming, so im learning the basics of programing...

my assigment is that i have to replace a word from a sentence to a different word

i.e

have a happy happy christmas

i have to change happy to horrible

the output sentence should look like this

have a horrible happy christmas

how do i change happy to horrible?

and + the concept of how i wrote it...am i goign the right direction or no

this is how i written my program.....any suggestions would do, iw oudl aprreciate it

import java.util.*;

public class LastName

{

public static void main (String[] args)

{

String name;

int space1 ;

int length;

String newname;

int space2;

int space3;

int space4;

Scanner keyboard = new Scanner (System.in);

// prompt the user

System.out.print ("Enter Sentence: ");

name = keyboard.nextLine ();

space1 = name.indexOf ( " ");

length = name.length();

newname = name.substring (0,18);

space2 = newname.indexOf (" ");

System.out.print ("Enter Sentence: ");

System.out.println (newname);

}

}

[1210 byte] By [theone2k7a] at [2007-11-26 19:31:17]
# 1
Have a look at the replaceFirst(...) method from the String class: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html
prometheuzza at 2007-7-9 22:01:16 > top of Java-index,Java Essentials,Java Programming...
# 2
my guess is that the teacher wouldn't want students to use replaceFirst as that would not teach them much. (other than libraries are cool things).
dmbdmba at 2007-7-9 22:01:16 > top of Java-index,Java Essentials,Java Programming...