OOPM: java program for reverse of number

//reverse of number w/o recursion
import java.io.*;

class Rev{
public static void main(String args[])
{
int n;
n = Integer.parseInt(args[0]);
while(n!=0)
{
System.out.print(n%10);
n/=10;
}
}
}

***********************************************************

//reverse of number with recursion
import java.io.*;

class revNum
{
void rev(int n)
{
if(n<10)
System.out.println(n);
else
{
System.out.print(n%10);
rev(n/10);
}
}
}

class RevRec{
public static void main(String args[])
{
int n;
n = Integer.parseInt(args[0]);
revNum r = new revNum();
System.out.print(“Reverse of number:”);
r.rev(n);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s