(Disarium number & reverse a number)

Design a menu driven program, that accepts an integer and displays the following menu : Displays the reverse of the number Displays whether the number is a Disarium number or not(Disarium number is a number whose digits raised to the power of their unit places sum is equal to the number. For example 135=11+32+53=1+9+125=135) exit

import java.util.*;
class Q1
{
    public static void main()
    {
        System.out.println("Enter your choice");
        Scanner s=new Scanner(System.in);
        System.out.println("1:- reverse a number\n2:-checking the number disarium or not\n3:-exit");
        int c=s.nextInt();
        switch(c)
        {
            case 1:
            System.out.println("Enter the number");
            int n=s.nextInt();
            int rev=0;
            while(n!=0)
            {
                int rem=n%10;
                rev=(rev*10)+rem;
                n/=10;
            }
            System.out.println("Reversed number is:"+rev);
            break;
            case 2:
            System.out.println("Enter a number");
            int num=s.nextInt();
            int a=num;
            String nu=String.valueOf(num);
            int i=nu.length();
            int sum=0;
            while(num!=0)
            {
                int rem=num%10;
                sum+=(Math.pow(rem,i));
                i--;
                num/=10;
            }
            if(a==sum)
            System.out.println("It is a Disarium number");
            else
            System.out.println("it is not a Disarium number");
            break;
            case 3:
            System.exit(0);
            break;
            default:
            System.out.println("Invalid number");
        }
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here