Disarium Number

Write a program to check it is Disarium number (unhappy number) or not .

import java.util.Scanner;
class Disarium
{
    public static void main()
    {
        System.out.println("Enter a number");
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int num=x,length=0,disarium=0,y=x;
        for(;x>0;length++)
            x=x/10;
        for(int i=length;y>0;i--)
        {
            disarium =  (int)Math.pow((y%10),i) + disarium;
            y=y/10;
        }
        if(num==disarium)
        System.out.println("It is disarium number");
        else
        System.out.println("It is not disarium number");
    }
}

For any desired program, please comment below. We will try our best to make that program available.

Comments

Popular Posts