Question 49 : Write a program in Java to reverse any integer ( with any number of digits ) taken as input by the user.
Sample input : 12345
Sample output : 54321
Java Program :
class rev
{
static void cal(int n)
{
int rev=0;
while(n>0)
{
rev=(rev*10)+(n%10);
n=n/10;
}
System.out.print("The reversed number : "+rev);
}
}
Sample input : 12345
Sample output : 54321
Java Program :
class rev
{
static void cal(int n)
{
int rev=0;
while(n>0)
{
rev=(rev*10)+(n%10);
n=n/10;
}
System.out.print("The reversed number : "+rev);
}
}
No comments:
Post a Comment