Results 1 to 6 of 6
- 02-02-2013, 03:32 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 7
- Rep Power
- 0
Java simple assignment help!! beginner
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.
- 02-02-2013, 03:40 AM #2
Senior Member
- Join Date
- Feb 2012
- Posts
- 219
- Rep Power
- 10
Re: Java simple assignment help!! beginner
What have you written so far? We won't really write code for you, but will guide and help with errors.
- 02-03-2013, 12:32 AM #3
Member
- Join Date
- Sep 2012
- Posts
- 7
- Rep Power
- 0
Re: Java simple assignment help!! beginner
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";
}
}
- 02-03-2013, 12:39 AM #4
Senior Member
- Join Date
- Feb 2012
- Posts
- 219
- Rep Power
- 10
Re: Java simple assignment help!! beginner
A substring would work. Have you looked at the javadoc for substring? Keep in mind there are two overloaded versions. Think about how you would go through a string and pick out words. You would need some form of a loop.
I should probably mention that Java has some nice built in utilities that will make this a lot easier. It looks like you are just starting out, so I am assuming that the book wants you to think of your own way of solving it without using Java's implementation. If this is an assignment from a book, then they probably discussed String manipulation in the chapter and maybe they do want you to use the String methods.Last edited by Wnt2bsleepin; 02-03-2013 at 01:15 AM.
- 02-03-2013, 12:42 AM #5
Senior Member
- Join Date
- Feb 2010
- Posts
- 128
- Rep Power
- 0
Re: Java simple assignment help!! beginner
what about:
...code removedLast edited by doWhile; 02-03-2013 at 01:08 AM. Reason: removed spoonfeeding
Measuring programming progress by lines of code is like measuring aircraft building progress by weight.
- 02-03-2013, 01:08 AM #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,638
- Rep Power
- 13
Similar Threads
-
I need help on a simple java assignment
By Avey in forum New To JavaReplies: 1Last Post: 10-30-2012, 08:24 PM -
Simple Java questions from beginner (creating variable help)
By bbfunk in forum New To JavaReplies: 5Last Post: 10-16-2012, 01:10 PM -
Beginner Java assignment
By darstar007 in forum New To JavaReplies: 6Last Post: 01-24-2012, 08:22 PM -
JAVA Beginner - Simple Program help
By Logik22 in forum New To JavaReplies: 13Last Post: 07-15-2011, 02:44 PM -
Java beginner, need some help on a simple tutorial? :D
By mootxico in forum New To JavaReplies: 1Last Post: 03-15-2009, 03:50 PM
Bookmarks