Question 8 : Write a program in Java to print the reverse of a three digit number given by the user.
Sample input : 145
Sample output : 541
Java Program :
class reverse
{
static void main(int d)
{
int a=0;
int e=0;
int b=0;
int c=0;
int s=0;
a=d%10;
e=d/10;
b=e%10;
c=d/100;
s=(a*100)+(b*10)+c;
System.out.println("The reversed number : "+s);
}
}
Input :
145
Output :
The reversed number : 541
Sample input : 145
Sample output : 541
Java Program :
class reverse
{
static void main(int d)
{
int a=0;
int e=0;
int b=0;
int c=0;
int s=0;
a=d%10;
e=d/10;
b=e%10;
c=d/100;
s=(a*100)+(b*10)+c;
System.out.println("The reversed number : "+s);
}
}
Input :
145
Output :
The reversed number : 541
Thanks.
ReplyDeletetanq
ReplyDeleteVery nice. For more examples visit http://answersz.com
ReplyDeleteHow to reverse a number containing any number of digits??
ReplyDelete