Java program to check disarium number


Java program to check disarium number


import java.util.*;

class disarium

{

public static void main()

{

Scanner Sc=new Scanner (System.in);

System.out.println("Enter a number:");
int a=Sc.nextInt();

String s=Integer.toString(a);

int aa=s.length();

int p,q,z=0,n=a;

while(n>0)

{p=n%10;

z=z+(int)Math.pow(p,aa);

aa--;
n=n/10;

}

if(z==a)

System.out.println("Disarium");  

else

System.out.println("NOT DISARIUM");

}

}

Java program to check disarium number
Java program to check disarium number




Output:-  Enter a number    89
                Disarium

Java program to check disarium number
Java program to check disarium number

No comments:

Powered by Blogger.