Recursion

Reverse A Number By Recursion


import java.util.*;
class S
{ 
 static int sum = 0;

 int reverse(int number)
 { 
  
  if(number != 0)
  {
   sum = (sum * 10) + (number % 10);  
   number = number/10;
   reverse(number);     
  }          
  return sum ;
 }

 public static void main(String[] args)
 {
  System.out.print("Enter The Number You Want To Reverse : ");
  Scanner sc = new Scanner(System.in);
  int num = sc.nextInt();
  
  S s1 = new S(); 
  System.out.print("Reverse Number Is : " + s1.reverse(num) );
 
 }

}