Reverse of a number in java

Reverse of a number in java. Reversing the integer is to print the integer digits in reverse order. This can be done by separating the individual digits from integer and store in the reverse order to a variable. This concept is most likely related to find palindrome, digit sum, digit product. Here is the java program to reverse a number.

Reverse of a number in java

class Reverse
{
    public static void main(String args[])
    {
        int i,a=0;
        i=Integer.parseInt(args[0]);
        while(i!=0)
        {    
            a=i%10+a*10;
            i=i/10;
        }
        System.out.println(a);
    }
}

Output :

 

Reverse of a number in java


2 thoughts on “Reverse of a number in java”

Add Comment Register



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>