Wednesday, 11 January 2017

Program-To reverse a number using recursion 


  1. import java.util.*;
  2.  class ReverseNumber{
  3.  public static void Reverse(int n)
  4.  {
  5.  int l;
  6.  if(n<10)
  7.  {
  8. System.out.print(n);
  9.  }
  10.  else
  11.  {
  12.  l=n%10;
  13.  n=n/10;
  14.  System.out.print(l);
  15.  Reverse(n);
  16.  }
  17.  
  18.  }
  19.  public static void main(String args[])
  20.  {
  21.  int n;
  22.  Scanner ob=new Scanner(System.in);
  23.  System.out.println("Enter the number");
  24.   n=ob.nextInt();
  25.  System.out.println("Reverse of the number is");
  26.  Reverse(n);
  27.  
  28.  
  29.  }
  30.  }

No comments:

Post a Comment