Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: How do I get this to work? Easy question, I'm just hopeless at it!

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy How do I get this to work? Easy question, I'm just hopeless at it!

    This is a string reverse so it should just reverse a word you input into the string. My problem is I dont know how to input a word into the string...help please!!!

    The code:

    public class rev {

    public static String rev (String s) {
    String to_return = "";
    while(true) {
    if(s.equals("")) return to_return;

    char c = s.charAt(0);
    to_return += c;
    s=s.substring(1);


    }

    }

    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How do I get this to work? Easy question, I'm just hopeless at it!

    Might want to check out the Scanner class.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I get this to work? Easy question, I'm just hopeless at it!

    I had a look into this and I think your right about the scanner class but it still confuses me in how to get the string to work?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How do I get this to work? Easy question, I'm just hopeless at it!

    Not really sure what you mean. What have you tried? What are you stuck?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I get this to work? Easy question, I'm just hopeless at it!

    Well I want it to reverse the word "hello" to "olleh". But I don't know how to tell the java string above to do it.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How do I get this to work? Easy question, I'm just hopeless at it!

    Quote Originally Posted by akmi5 View Post
    Well I want it to reverse the word "hello" to "olleh". But I don't know how to tell the java string above to do it.
    That's the whole point of your assignment, is it not? So we can't just do it for you. Look at the String API for several useful functions.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I get this to work? Easy question, I'm just hopeless at it!

    Its not an assignment, its revision for my exam later this month. I've got about 40 different methods to learn and I need to learn how to do one well so I can use that as a template for the rest to learn etc.. So could you tell me how to make it run please? I've wasted enough time trying to get it to run its becoming stressful!

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How do I get this to work? Easy question, I'm just hopeless at it!

    Think about how you'd do this in your head, or with a piece of paper and a pencil. Not just for short words, but for really long words that you can't always just switch in your head.

    Recommended reading: http://www.javaprogrammingforums.com...e-posting.html
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Exception in JUnit test (easy question)
    By opium in forum Exceptions
    Replies: 1
    Last Post: February 14th, 2012, 09:09 AM
  2. jSSC library - for easy work with serial ports
    By scream3r in forum Java SE API Tutorials
    Replies: 4
    Last Post: July 19th, 2011, 09:36 AM
  3. jSSC library - for easy work with serial ports
    By scream3r in forum Java Code Snippets and Tutorials
    Replies: 3
    Last Post: April 13th, 2011, 03:29 PM
  4. Easy array question
    By surfbumb in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2011, 09:44 PM
  5. Quick easy Java question.
    By DHG in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 25th, 2011, 03:59 PM

Tags for this Thread