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();
}
}

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is senior ICT professional who talks about #it, #cloud, #servers, #software, and #innovation. Rabins is also the first initiator of Digital Nepal. Facebook: rabinsxp Instagram: rabinsxp

You may also like...

Leave a Reply

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