Advertisements
Advertisements
Question
Write a program to create the reverse of a number and print it.
Code Writing
Advertisements
Solution
import java.util.*;
class clDigits
{
void main()
{
Scanner sc = new Scanner(System.in);
int N, revn = 0, cn = 0, d = 0;
System.out.print("Enter a number : ");
N = sc.nextInt();
cn = N;
while(cn > 0)
{
d = cn % 10;
revn = revn * 10 + d;
cn = cn / 10;
}
System.out.print(" Reverse of : " + N + " is : " + revn);
}
}
Output:
Enter a number : 357
Reverse of: 357 is: 753
shaalaa.com
Is there an error in this question or solution?
