java code to reverse a signed integer code example
Example 1: java code to reverse an integer
public class ReverseNumberExample1
{
public static void main(String[] args)
{
int number = 987654, reverse = 0;
while(number != 0)
{
int remainder = number % 10;
reverse = reverse * 10 + remainder;
number = number/10;
}
System.out.println("The reverse of the given number is: " + reverse);
}
}
Example 2: reverse a integer in java
while(num != 0)
{
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}