Program-To reverse a number using recursion
- import java.util.*;
- class ReverseNumber{
- public static void Reverse(int n)
- {
- int l;
- if(n<10)
- {
- System.out.print(n);
- }
- else
- {
- l=n%10;
- n=n/10;
- System.out.print(l);
- Reverse(n);
- }
- }
- public static void main(String args[])
- {
- int n;
- Scanner ob=new Scanner(System.in);
- System.out.println("Enter the number");
- n=ob.nextInt();
- System.out.println("Reverse of the number is");
- Reverse(n);
- }
- }
No comments:
Post a Comment