WAP to reverse digits of an integer in java

import java.io.*;
class Reverse
{
public static void main(String args[])
{
BufferedReader bf=new BufferedReader( new InputStreamReader(System.in));
int a=0,c=0,sum=0;
try
{
System.out.println("Enter the number to find Reverse:");
a=Integer.parseInt(bf.readLine());
}
catch(Exception e)
{
  e.printStackTrace();
}
while (a>0)
{
c=a%10;
sum=sum*10;
sum=c+sum;
  a=a/10;
}
System.out.println("Reverse of  number is:"+sum);
}
}


 

Comments