Help me with my 1st Java Assignment! Stuck!!
My first assignment is from Savitch's book "Absolute Java". Here is the problem:
Q: Write a program that starts with a line of text and then outputs that line of text with the first occurence of "hate" changed to "love". For example, a possible sample output might be
The line of text to be changed is:
I hate you.
I have rephrased that line to read:
I love you.
You can assume that the word "hate" occurs in the input. If the word "hate" occurs more than once in the line, your program will replace only the first occurrence of "hate". Since we will not discuss input until chapter 2, use a defined constant for the string to be changed. To make your program work for another string, you should only need to change the definition of this defined constant.
Re: Help me with my 1st Java Assignment! Stuck!!
Do you have any specific questions about your assignment?
Please post your code and any questions about problems you are having.
Look at the String class and its methods:
Java Platform SE 7
Re: Help me with my 1st Java Assignment! Stuck!!
Quote:
Originally Posted by
Norm
Do you have any specific questions about your assignment?
Please post your code and any questions about problems you are having.
Look at the String class and its methods:
Java Platform SE 7
I'm really confused, thought of using substring since it is mentioned in the chapter 1, but I dont know how
this is what i got
public class TextCHange {
public static void main(String[] args) {
String Text1 = "I hate you and they love you";
}
}
Re: Help me with my 1st Java Assignment! Stuck!!
I'm really confused, thought of using substring since it is mentioned in the chapter 1, but I dont know how
this is what i got
public class TextCHange {
public static void main(String[] args) {
String Text1 = "I hate you and they love you";
}
}
Re: Help me with my 1st Java Assignment! Stuck!!
Now you need to use a String class method to locate the part of the String (the substring) that you want to replace.
There are several methods in the String class that will help you. Read the API doc for the String class and try some of the methods. Use the System.out.println() method to print out the results to see what the method does.