write a program in java to print disarium number
Answers
Answered by
0
- public class DisariumNumber.
- {
- //calculateLength() will count the digits present in a number.
- public static int calculateLength(int n){
- int length = 0;
- while(n != 0){
- length = length + 1;
- n = n/10;
Answered by
5
import java.util.*;
class Disarium
{
public static void main()
{
Scanner sc= new Scanner (System.in);
{
System.out.println(" Enter a number");
int num= sc.nextInt();
int c=num,d=0,sum=0;
String s= Integer.toString(num);
int l= s.length();
while(c>0)
{
d=c%10;
sum=sum+(int)Math.pow(d,l);
l--;
c=c/10;
}
if(sum==num)
System.out.println("Disarium number");
else
System.out.println("Not a Disarium number");
}
}
Similar questions