how do we reverse the digits .
like if i were given 12345
and i were to convert it to 54321.
Printable View
how do we reverse the digits .
like if i were given 12345
and i were to convert it to 54321.
There are many ways. You have no idea? And do you have/(want the result) the digit as an integer or as a string?
integer.
actuallu i wanna make GUI reverse number program
System.out.println(new StringBuilder(String.valueOf(12345)).reverse());
or use the mathematic :)
or or or....no own further ideas? ;(Code:int digit = 12345;
while (digit != 0) {
int tmp = digit % 10;
digit /= 10;
System.out.print(tmp);
}
The GUI to get the number and show the reverse is one thing to code.
The code to do the reversing is another thing.
They can be done separately.
In the example you posted, does it make any difference if the characters are numeric digits: 0-9 or can they be anything like letters or special characters: A, b, { etc
What should be the reverse of, say, 100? 001? or 1?
kind regards,
Jos
could you provide me with the code
No, but we will help you get your code working.
What do you have now? What is your algorithm or design for solving this problem?
What would be the use of that? We give you the code; you turn it in as if you wrote it; you get a fine grade; you get a job somewhere and we end up having to do your work because you know zilch about programming. capiche? It would be much better if you give it a try on your own; if you get stuck come back here and we'll try to help you out.
kind regards,
Jos
Do it via the string route.
Psuedo code.
Declare String initializing it with int // hint Integer class
Declare temp String
Loop through String length in reverse
Concatenate temp with charAt
The temp String will be the reverse of the int String.