Write a program to print Reverse Digits of given numbers.
You are given a number n , Write a program to reverse digits of n.
Input Format
For each test case, you will get an integer input.
Constraints
1<=n<=10^4
Output Format
Print the reverse
Sample Input 0
1234
Sample Output 0
4321
Explanation 0
Print the reverse number .
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int reverseDigits(int n) {
int reverse = 0;
while(n > 0){
reverse = reverse * 10 + n % 10;
n = n / 10;
}
return reverse;
}
public static void main (String[] args){
Scanner sc=new Scanner(System.in);
int n = sc.nextInt();
System.out.println(reverseDigits(n));
}
}
Also Read: