Wednesday, 11 January 2017

Program-To reverse a number using function  



  1. import java.util.*;
  2.  class ReverseNumber{
  3. public static int r=0,l;
  4. public static void Reverse(int n){
  5.  
  6.  while(n>0)
  7.  {
  8.    l=n%10;
  9.            r=(r*10)+l;
  10.            n=n/10;   
  11.  }
  12.  System.out.println(r);
  13.  }
  14.  public static void main(String args[])
  15.  {       
  16.      int n;
  17.  Scanner ov=new Scanner(System.in);
  18.  System.out.println("Enter the number");
  19.  n=ov.nextInt();
  20.  System.out.println("Reverse of the number is:");
  21.  Reverse(n);
  22.  }
  23.  }

No comments:

Post a Comment