1. Member
Join Date
Sep 2008
Posts
29
Rep Power
0

## Reversing

how do you reverse an int, and add it to another int...

2. use the modulus operator and create a new string of the reversed int then concat, convert the second int to string, concat together and print.

3. reverse an int
what is reversing an int? What base are you using?
If the int (in binary is) 1010 (decimal 10)
then reversed would be 0101 (decimal 5)

4. Originally Posted by Norm
what is reversing an int? What base are you using?
If the int (in binary is) 1010 (decimal 10)
then reversed would be 0101 (decimal 5)
I'm confused too.

More specifically this process is call, bitwise complement.

5. Poor example. Let me expand it.
Looking at the contents of an int in binary could be:
000001010
reversing the order of the bits would be
010100000
Not the compliment which would be:
111110101

6. Member
Join Date
Sep 2008
Posts
29
Rep Power
0
like

int reverse = 15;

how do i reverse int reverse to 51?

7. Java Code:
```        int n = 15;
String s = String.valueOf(n);
String reverse = "";
for(int i = s.length()-1; i >= 0; i--) {
reverse += String.valueOf(s.charAt(i));
}
int reversed = Integer.parseInt(reverse);
System.out.printf("n = %d  reversed = %d%n",
n, reversed);```

8. How do you expect the OP to think and learn programming if you give him the code? He'll be great with select, copy and paste, but what will he do when you're not there?
I'd think a student would get more satisfaction figuring out how to do something himself.

9. Originally Posted by Norm
How do you expect the OP to think and learn programming if you give him the code? He'll be great with select, copy and paste, but what will he do when you're not there?
I'd think a student would get more satisfaction figuring out how to do something himself.
I agreed with you Norm. Most of newbies in Java just looking a code, not showing any attempt themselves. I don't know why they are doing like that. Most of the time, if they not found any solution in quick time just left the forum and registered in another. For me it's too bad habit.

10. Member
Join Date
Sep 2008
Posts
29
Rep Power
0
hahahah, well you know what lol, i am teaching myself java by trying, i've been working on figuring out how to do that for close to 2 months, and i havn't found a way, all the codes i show you or ask help with are codes i have tried for at least a month, and gotten too frusterated to keep working.

11. Member
Join Date
Sep 2008
Posts
29
Rep Power
0
do you want me to post all the codes i tried>>?

12. you don't have to post all of it. post anything that gives us the impression you actually tried to figure it out yourself first

13. Originally Posted by xcallmejudasx
you don't have to post all of it. post anything that gives us the impression you actually tried to figure it out yourself first
Yes, this is what I expecting. When you get the error, that message contain the line number where the error pops in your code. So you can simply post that part of the code initially with the explanation what you are going to do. If others not enough that code segment to answer your question, then post other relevant code segment.

#### Posting Permissions

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