## Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

# Write a Java program to print the entered number in reverse?

Reversing a number involves swapping the digit at the first position with the last digit and the second digit with the second last digit, and so on until the middle digit.

Here are the steps to reverse the number.

• Take the number modulo you want to reverse by ten.
• To determine the reverse number, multiply it by ten and add the modulo value.
• Now divide the number by ten.
• Until the number reaches zero, repeat the above steps.

Now let’s look at the below Java program that prints the number in reverse order.

``````import java.util.Scanner;
public class Reverse
{
public static void main(String args[])
{
int x, y, k = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number you want to reverse:");
x = s.nextInt();
while(x > 0)
{
n = x % 10;
k = k * 10 + y;
x = x / 10;
}
System.out.println("Reverse number is "+k);
}
}
``````

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing