Computer Science, asked by kanaksringaryan7, 5 months ago

a) Write a Program in Java to input a number and check whether it is a Disarium Number or not. Note: A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number.

For example 135 is a DISARIUM

(Workings 11+32+53 = 135, some other DISARIUM are 89, 175, 518 etc)

in java​

Answers

Answered by amit05s0101
1

Answer:

please mark me a BRAINIEST

Answered by samarthkrv
0

Answer:

public class DisariumNumber {

static int len(int n){

 int temp = n, len = 0;

   while(temp!=0){

     len++;

     temp/=10;

   }

return len;

}

public static boolean isDisarium(int n) {

  int sum = 0 , temp = n , l = len(n);

    while(temp!=0){

      int r = temp%10;

      sum += (int)(Math.pow(r,l));

      l--;

      temp/=10;

    }

return sum == n;

}

}

Explanation:

Similar questions