Results 1 to 6 of 6
  1. #1
    xemkruz2012 is offline Member
    Join Date
    Sep 2012
    Posts
    7
    Rep Power
    0

    Default 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.

  2. #2
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default 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.

  3. #3
    xemkruz2012 is offline Member
    Join Date
    Sep 2012
    Posts
    7
    Rep Power
    0

    Default 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";

    }
    }

  4. #4
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default 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 02:15 AM.

  5. #5
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default Re: Java simple assignment help!! beginner

    what about:


    ...code removed
    Last edited by doWhile; 02-03-2013 at 02:08 AM. Reason: removed spoonfeeding
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Java simple assignment help!! beginner

    @FlyNn, please be cognizant of the difference between helping someone do their work vs giving them the answer. One of the hardest parts of programming is problem solving, and being spoonfed an answer does nothing to help one tune these essential skills.

Similar Threads

  1. I need help on a simple java assignment
    By Avey in forum New To Java
    Replies: 1
    Last Post: 10-30-2012, 09:24 PM
  2. Replies: 5
    Last Post: 10-16-2012, 02:10 PM
  3. Beginner Java assignment
    By darstar007 in forum New To Java
    Replies: 6
    Last Post: 01-24-2012, 09:22 PM
  4. JAVA Beginner - Simple Program help
    By Logik22 in forum New To Java
    Replies: 13
    Last Post: 07-15-2011, 03:44 PM
  5. Replies: 1
    Last Post: 03-15-2009, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •