Java

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 the owner of RabinsXP who is constantly working for increasing the Internet of Things (IoT) in Nepal. He also builds android apps and crafts beautiful websites. He is also working with various social services. The main aim of Lamichhane is to digitally empower the citizens of Nepal and make the world spiritually sound better both in terms of technology and personal development. Rabins is also the first initiator of Digital Nepal.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button