Reverse word for Java code HELP!

Discussion in 'Java' started by usatoday, Jan 5, 2011.

  1. usatoday

    usatoday Guest

    I got to finish this project by tomorrow, but I really don't know how
    to. If I don't finish it, I will be doomed:( I don't understand java
    AT ALL, I AM A JAVA IDIOT. Please help me! your help will be
    appreciated!

    The project is Reversewords.
    We have to design a function that will take a string of words and hand
    it back to the caller with all the words reversed (E.g. "i like you"
    becomes "you like i"). Use two nested for loops in the routine to get
    your result. Afterwards, in the main, continue asking the user for a
    sentence- or just type return to end (can use while loop in main).

    this is what I got so far.

    public class Reversewords
    {
    public static void main(String [] args)
    {
    Scanner inputreader=new Scanner(System.in);
    int 0 = sen.getLength()-1;
    int c = 0;
    }
    for (c=orj; c>0; c--)
    {
    if (sen.charAt(c)=='')
    {
    String sb = sen.substring(c+1,ori+1);
    system.out.print(sb)" ";
    ori = c;
    }
    }
    usatoday, Jan 5, 2011
    #1
    1. Advertising

  2. On 05/01/2011 13:59, usatoday wrote:
    > I got to finish this project by tomorrow, but I really don't know how
    > to. If I don't finish it, I will be doomed:( I don't understand java
    > AT ALL, I AM A JAVA IDIOT. Please help me! your help will be
    > appreciated!


    Relax, if you don't understand Java and are a Java idiot, it would be
    unkind to propel you into a job where you need to know Java.

    Chill out and spend the time looking for some course subjects that you
    actually enjoy and are motivated to learn.

    --
    RGB
    RedGrittyBrick, Jan 5, 2011
    #2
    1. Advertising

  3. usatoday

    Luuk Guest

    On 05-01-11 14:59, usatoday wrote:
    > I got to finish this project by tomorrow, but I really don't know how
    > to. If I don't finish it, I will be doomed:( I don't understand java
    > AT ALL, I AM A JAVA IDIOT. Please help me! your help will be
    > appreciated!
    >
    > The project is Reversewords.
    > We have to design a function that will take a string of words and hand
    > it back to the caller with all the words reversed (E.g. "i like you"
    > becomes "you like i"). Use two nested for loops in the routine to get
    > your result. Afterwards, in the main, continue asking the user for a
    > sentence- or just type return to end (can use while loop in main).
    >
    > this is what I got so far.
    >
    > public class Reversewords
    > {
    > public static void main(String [] args)
    > {
    > Scanner inputreader=new Scanner(System.in);
    > int 0 = sen.getLength()-1;


    I did not know JAVA accepts numeric named variables...



    --
    Luuk
    Luuk, Jan 5, 2011
    #3
  4. On 2011-01-05, usatoday <> wrote:
    > I got to finish this project by tomorrow, but I really don't know how
    > to. If I don't finish it, I will be doomed:( I don't understand java
    > AT ALL, I AM A JAVA IDIOT. Please help me! your help will be
    > appreciated!


    Regardless of what you're actually trying to accomplish with the below
    program, it has a number of errors that will prevent it from even
    compiling.

    >
    > public class Reversewords
    > {
    > public static void main(String [] args)
    > {
    > Scanner inputreader=new Scanner(System.in);


    The compiler needs to be told where to find the Scanner class.

    > int 0 = sen.getLength()-1;


    You can't call something "0" and there is nothing called "sen".

    > int c = 0;
    > }
    > for (c=orj; c>0; c--)


    This for statement is outside of any method, and you probably want it
    to be inside of one. There is nothing called "orj".

    > {
    > if (sen.charAt(c)=='')


    '' isn't a valid character constant.

    > {
    > String sb = sen.substring(c+1,ori+1);


    Again, nothing is actually called "sen", and there is also nothing
    called "ori".

    > system.out.print(sb)" ";


    You can't follow a method call with an immediate ".

    > ori = c;


    And there is nothing called ori.

    > }
    > }


    Finally, the file seems to end before the class does.

    Cheers,

    Bent D.
    --
    Bent Dalager - - http://www.pvv.org/~bcd
    powered by emacs
    Bent C Dalager, Jan 5, 2011
    #4
  5. usatoday

    Roedy Green Guest

    On Wed, 5 Jan 2011 05:59:11 -0800 (PST), usatoday
    <> wrote, quoted or indirectly quoted someone who
    said :

    >I got to finish this project by tomorrow, but I really don't know how
    >to. If I don't finish it, I will be doomed:( I don't understand java
    >AT ALL, I AM A JAVA IDIOT. Please help me! your help will be
    >appreciated!
    >
    >The project is Reversewords.
    >We have to design a function that will take a string of words and hand
    >it back to the caller with all the words reversed (E.g. "i like you"
    >becomes "you like i"). Use two nested for loops in the routine to get
    >your result. Afterwards, in the main, continue asking the user for a
    >sentence- or just type return to end (can use while loop in main).
    >
    >this is what I got so far.
    >
    >public class Reversewords
    >{
    > public static void main(String [] args)
    > {
    > Scanner inputreader=new Scanner(System.in);
    > int 0 = sen.getLength()-1;
    > int c = 0;
    > }
    > for (c=orj; c>0; c--)
    > {
    > if (sen.charAt(c)=='')
    > {
    > String sb = sen.substring(c+1,ori+1);
    > system.out.print(sb)" ";
    > ori = c;
    > }
    >}


    you are flummoxing. See http://mindprod.com/jgloss/tackling.html for
    how to break the problem into manageable pieces.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    To err is human, but to really foul things up requires a computer.
    ~ Farmer,s Almanac
    It is breathtaking how a misplaced comma in a computer program can
    shred megabytes of data in seconds.
    Roedy Green, Jan 6, 2011
    #5
  6. usatoday

    Eric Sosman Guest

    On 1/5/2011 8:59 AM, usatoday wrote:
    > I got to finish this project by tomorrow, but I really don't know how
    > to. If I don't finish it, I will be doomed:( I don't understand java
    > AT ALL, I AM A JAVA IDIOT. Please help me! your help will be
    > appreciated!
    >
    > The project is Reversewords.
    > We have to design a function that will take a string of words and hand
    > it back to the caller with all the words reversed (E.g. "i like you"
    > becomes "you like i").[...]


    Suggested solution method: First, find the length of the original
    string; for "i like you" this would be ten. Then generate all ten-
    character strings in turn, and append each to "i like you". Test
    each concatenation to see whether it's a palindrome; if it is, the
    generated string is the reverse of the original!

    --
    Eric Sosman
    lid
    Eric Sosman, Jan 6, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laura
    Replies:
    1
    Views:
    520
    Gunnar Hjalmarsson
    Jun 5, 2004
  2. Mr Smith

    Reverse java code to UML

    Mr Smith, Mar 11, 2005, in forum: Java
    Replies:
    4
    Views:
    666
    Hal Rosser
    Mar 12, 2005
  3. dogbite
    Replies:
    4
    Views:
    683
    osmium
    Oct 10, 2003
  4. ram
    Replies:
    9
    Views:
    415
    Roedy Green
    Aug 23, 2007
  5. Replies:
    13
    Views:
    805
    santosh
    Oct 4, 2007
Loading...

Share This Page