Programming Tutorials

Reverse a number in Java

By: Paawan Chaudhary in Java Tutorials on 2012-09-19  

This java program defines a class having one 3-digit number, num as data member. Initializes and displays reverse of that number.

import java.lang.*;
class q1Reverse
{
	int num,r=0,s=0;
	q1Reverse(int n)
	{
		num = n;
	}
	void Reverse()
	{
		while(num>0)
		{
			r=num%10;
			s=(s*10)+r;
			num=num/10;
		}
		System.out.println("Reverse of number ="+s);
	}
	public static void main(String args[])
	{
		q1Reverse r1 = new q1Reverse(786);
		r1.Reverse();
	}
}





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)