Results 1 to 18 of 18

Thread: nice question

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default nice question

    how to reverse the strings in a line

    ex
    given :-hello world

    o/p should be :-olleh dlrow

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yeah, what you've tried so far?

    Just a hint, you've a line of text (with few words). First of all collect all the words in the sentence and then think how to alter the position of letters in a word. Try something and let us know.

  4. #4
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    Java Code:
    // ... code deleted
    Last edited by Fubarable; 06-26-2010 at 07:36 PM.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,734
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by JvlShz View Post
    Java Code:
    //... code deleted
    Please stop the spoonfeeding; most of the OPs will only copy and paste the boilerplate code and learn nothing; you take the risk that such an OP becomes a coworker and you have to solve all his/her problems.

    kind regards,

    Jos
    Last edited by Fubarable; 06-26-2010 at 07:37 PM.

  6. #6
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Please stop the spoonfeeding; most of the OPs will only copy and paste the boilerplate code and learn nothing; you take the risk that such an OP becomes a coworker and you have to solve all his/her problems.

    kind regards,

    Jos

    dang - never thought of it that way

    I was just trying to help this guy by using like 20 seconds of my life :P

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    Have you heard the one about "Giving a man a fish vs Teaching a man to fish"?
    What happens when the OP has another problem? Will you be there to help him?
    Or will he know how to debug and solve his own problems?

  8. #8
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Have you heard the one about "Giving a man a fish vs Teaching a man to fish"?
    What happens when the OP has another problem? Will you be there to help him?
    Or will he know how to debug and solve his own problems?
    ima newbie to programming too so it kinda helps me too when I help people

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,734
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by JvlShz View Post
    ima newbie to programming too so it kinda helps me too when I help people
    You are not helping them by spoonfeeding them; don't do it. Of course you can be proud of knowing how to solve such trivialities but don't feed them to beginners but use them in your own code; other people have to learn too and spoonfeeding them just makes them lazy.

    kind regards,

    Jos

  10. #10
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    ok how about this then (pseudocode)

    Java Code:
    lamda reverse ( input ) {
     split[] = input->split("\\s+");
     out = '';
     foreach (splitted : split) {
      out .= splitted->reverse() . ' ';
     }
     out = sub_string(out, 0, string_length(out) - 1);
     return out;
    }

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,734
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by JvlShz View Post
    ok how about this then (pseudocode)

    Java Code:
    lamda reverse ( input ) {
     split[] = input->split("\\s+");
     out = '';
     foreach (splitted : split) {
      out .= splitted->reverse() . ' ';
     }
     out = sub_string(out, 0, string_length(out) - 1);
     return out;
    }
    That is just confusing the reader; you are using operators '.=' and '->' that don't mean anything outside of Java; mentioning the existence of StringBuilders (or StringBuffers) and the String.split( ... ) method is more than enough.

    kind regards,

    Jos

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    After you've solved the problem, try to think of a way to show the OP how to follow the path that you took.

  13. #13
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    After you've solved the problem, try to think of a way to show the OP how to follow the path that you took.
    1) Split by spaces
    2) Rejoin each part, backwards
    3) Output

    Quote Originally Posted by JosAH View Post
    That is just confusing the reader; you are using operators '.=' and '->' that don't mean anything outside of Java; mentioning the existence of StringBuilders (or StringBuffers) and the String.split( ... ) method is more than enough.

    kind regards,

    Jos
    Sorry, thats just how I write pseudocode

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,734
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by JvlShz View Post
    Sorry, thats just how I write pseudocode
    Fine with me but then you have to explain your private notation; better use ordinary (English) text. If you reply here you have to explain stuff to the OPs, not show how clever you are.

    kind regards,

    Jos

  15. #15
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Fine with me but then you have to explain your private notation; better use ordinary (English) text. If you reply here you have to explain stuff to the OPs, not show how clever you are.

    kind regards,

    Jos
    im not clever, just a normal kid whose tryin to help

    to explain better:

    -> translates to . (c++ syntax -> java syntax)
    .= translates to += (perl syntax -> java syntax)

  16. #16
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,734
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by JvlShz View Post
    im not clever, just a normal kid whose tryin to help

    to explain better:

    -> translates to . (c++ syntax -> java syntax)
    .= translates to += (perl syntax -> java syntax)
    We acknowledge your spirit to help; much appreciated, but helping is not spoonfeeding; remember that.

    kind regards,

    Jos

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    Please stop the spoonfeeding; most of the OPs will only copy and paste the boilerplate code and learn nothing; you take the risk that such an OP becomes a coworker and you have to solve all his/her problems.

    kind regards,

    Jos
    I'm totally agreed with you Jos. In most of the thread this is happening, OPs are just waiting for a code from another members. Once he/she found that never comes back, and move with the code. Say he/she stuck with that code, then post another code saying that my code is not working, giving notion that it's his/her code written by themselves.

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JvlShz View Post
    ima newbie to programming too so it kinda helps me too when I help people
    You may doing that to helping out. But that is not the way lol. People not really learning from you. So don't do this next time, try to guide them on your initial posts, and with the move ahead you can modified his/her code and in that way helps a lot to learn.

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  2. Replies: 3
    Last Post: 03-10-2010, 06:51 PM
  3. Nice Forum
    By VijayKumar23 in forum Introductions
    Replies: 0
    Last Post: 04-15-2009, 01:22 PM
  4. [SOLVED] Building a nice GUI applet?
    By bobleny in forum New To Java
    Replies: 3
    Last Post: 05-09-2008, 08:42 PM
  5. JNI question
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-24-2007, 11:18 AM

Posting Permissions

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