• September 21st, 2011, 05:40 PM
Nemus
Hey!
Quick and simple question for you guys. I would like the user to enter any 2 digit numbers. Then, make those two numbers reverse.

Example: 92 would become 29. How do I do that?

Thank you.
• September 21st, 2011, 05:46 PM
copeg
What have you tried? Have you read the java tutorials over at Oracle (see the link in my signature)? Where are you stuck? Is there something confusing? See the following:
http://www.javaprogrammingforums.com...e-posting.html
• September 21st, 2011, 06:45 PM
wookyoo
show me how you have done so far or is there any idea to solve your problem?
• September 21st, 2011, 07:15 PM
Nemus
I figured it out! But now I'm stuck on another problem... I'm trying to enter a sentence and then make the first word of the sentence go to the end. As in:
Hello my name is Mat.

would be transformed into:

my name is Mat. Hello

Thanks!
• September 21st, 2011, 07:20 PM
copeg
Once again...what have you tried? You solved your first problem, evidence that you can probably tackle this problem as well. See the API for String, which contains a wealth of methods to help you accomplish this task.
• September 22nd, 2011, 10:46 AM
Nemus
Okay, here's where I'm at right now. However I found myself to be completely blocked from here on end, I don't think we covered this in class, probably why it's a bonus question.

Code :

```Scanner keyboard = new Scanner (System.in);   String space = " "; String sentence = keyboard.nextLine(); String[] tokens = sentence.split(space); String newSentence = "";   for (int i = 1; i<tokens.length; i++) { newSentence = sentence + space; } newSentence += tokens[0]; System.out.println(newSentence);```

When I enter Java is fun. it displays Java is fun Java so yah, that's the problem.

Thank you
• September 22nd, 2011, 11:50 AM
copeg
That's a darn good start, and I'm glad you think java is fun

Something that might help you is to debug this using some println statements (see Debugging with System.out.println) This lets you print out the logic of the program - you can then see what the variables are at different times and locations within the program. For example - how does newSentence change when you loop over the tokens? Often times just looking at these changes - writing down and following how the variables change - in a stepwise manner lets the solution jump right out.
• September 22nd, 2011, 06:50 PM
Nemus
Thanks, and I do like Java! However I don't find it user friendly at all!

Yah... I'm still stuck on this, I just can't my fingers on how to delete the first word of a string sentence after the word has been copied to the end of the sentence. If you could hint me or advise me anything, I would greatly appreciate it because this is starting to frustrate me :mad:. Thank you!
• September 22nd, 2011, 07:02 PM
newbie
You've actually performed what is required already, but you haven't imposed it in all the required areas.

Consider this:
newSentence = sentence + space;
What you're essentially saying is: myNewSentence = "Java is fun" + SPACE;.
Now you know that's not what you want.

But once you exit the loop, you extract a word from the array instead: newSentence += tokens[0];.
I.e - What you're saying is: newSentence = "Java is fun" + "Java";
Why don't you try taking that approach inside the for loop, and see where that gets you.

If you did take copeg's suggestion and use println statements to track what's happening, you would have gotten this a while back :P
• September 26th, 2011, 06:26 AM
RaviPKorra
public class Ex2 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}
• September 26th, 2011, 08:56 AM
copeg
The Problem with Spoon-feeding
• September 26th, 2011, 09:41 AM
Nemus
Why would you do that..? I did most of the code myself, I had one small problem and you keep sending me on wild goose chases. I thought this subforum was called What's wrong my code. You keep replying to my questions with even more questions...
• September 26th, 2011, 10:36 AM
copeg
Quote:

Originally Posted by Nemus
Why would you do that..? I did most of the code myself, I had one small problem and you keep sending me on wild goose chases. I thought this subforum was called What's wrong my code. You keep replying to my questions with even more questions...

I apologize if my time and knowledge, handed over to you unpaid and is considered leading you in wild goose chases is not appreciated, but handing over answers to a problem denies you of the learning process, ends up leading you in many more wild goose chases down the line - especially answers which show the poster handing over answers hasn't even read the problem at hand.
• September 27th, 2011, 06:56 AM
Mr.777
Example:
"Java is fun."
You want to take the first word in the end, right?
Did you hear about String? If no, find it out.
Split your main string into two strings.
1. Java 2. is fun.
Concatenate string2+string1.
Hope it will help.
Anyways, copeg and newbie has provided you a great help. If you can't take that, you will not be able to try this as well. Good luck
• September 29th, 2011, 01:23 PM
Razor1911