Go to Top

Friday, 8 April 2011

To reverse a three digit number

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

4 comments:

ShareThis