JAVA class with a 3 digit number data member and it’s initialize to display reverse

Write a program to define a class having one 3-digit number, a ‘num’ as a data member. Initialize and display 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();
}
}

Leave a Reply

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