Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Reverse word for Java code HELP!

Reply
Thread Tools

Reverse word for Java code HELP!

 
 
usatoday
Guest
Posts: n/a
 
      01-05-2011
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;
}
}
 
Reply With Quote
 
 
 
 
RedGrittyBrick
Guest
Posts: n/a
 
      01-05-2011
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
 
Reply With Quote
 
 
 
 
Luuk
Guest
Posts: n/a
 
      01-05-2011
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
 
Reply With Quote
 
Bent C Dalager
Guest
Posts: n/a
 
      01-05-2011
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-06-2011
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.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      01-06-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reverse word order to read it from right to left lovecreatesbea...@gmail.com C Programming 13 10-04-2007 06:31 PM
reverse engineering of java code ram Java 9 08-23-2007 12:22 AM
Word 2000 - reverse print order stopped working abc@nospam.nospam Computer Support 1 05-07-2006 02:39 PM
Reverse java code to UML Mr Smith Java 4 03-12-2005 01:58 AM
Stacks Queues Reverse Reverse Polish dogbite C++ 4 10-10-2003 05:06 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57