133. JAVA Program to find the Reverse of given numbers using recursion.
How does this program work?
- This program is used to find the Reverse of given numbers using recursion in java.
- By using recursion we can find the reverse of given numbers.
Here is the code
//To find the Reverse of given numbers using recursion
import java.util.Scanner;public class Reverse
{
public static void reverseMethod(int number )
{
if (number < 10)
{
System.out.println(number );
return;
}else
{
System.out.print(number % 10 );
//Method is calling itself: recursion
reverseMethod(number/10 );}
}
public static void main(String args[] )
{
int num=0;
System.out.println("Enter Number: " );
Scanner in = new Scanner(System.in );
num = in.nextInt();
System.out.print("Reverse of the input number is:" );
reverseMethod(num);
System.out.println();
}
}