Results 1 to 15 of 15
Thread: Reversing
- 11-04-2008, 12:35 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
- 11-04-2008, 12:39 AM #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.
- 11-04-2008, 01:04 AM #3reverse an int
If the int (in binary is) 1010 (decimal 10)
then reversed would be 0101 (decimal 5)
- 11-04-2008, 05:57 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
- 11-04-2008, 03:15 PM #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
- 11-04-2008, 05:28 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Ya, looking at your example for a minute I thought it's compliment.
- 11-04-2008, 10:30 PM #7
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
like
int reverse = 15;
how do i reverse int reverse to 51?
- 11-04-2008, 11:05 PM #8Java 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);
- 11-05-2008, 12:52 AM #9
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.
- 11-05-2008, 04:29 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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.
- 11-05-2008, 05:10 AM #11
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-05-2008, 05:19 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Ok, but the thing is I cannot see any code segment you have post here.
- 11-06-2008, 12:09 AM #13
Member
- Join Date
- Sep 2008
- Posts
- 29
- Rep Power
- 0
do you want me to post all the codes i tried>>?
- 11-06-2008, 12:26 AM #14
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
- 11-06-2008, 05:29 AM #15
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
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.
Similar Threads
-
Reversing String
By mew in forum New To JavaReplies: 4Last Post: 12-02-2007, 10:42 PM -
reversing Strings
By Java Tip in forum Java TipReplies: 0Last Post: 11-11-2007, 09:24 PM -
reversing a string
By toad in forum New To JavaReplies: 5Last Post: 11-07-2007, 10:13 AM
Bookmarks