Computer Science, asked by lakshmihari954, 1 day ago

Write a program in java to enter a number and check whetger the sum of the powers of the digits is equal to the number itself .

example: 1234
=1⁴+2⁴+3⁴+4⁴
=1234
this program must be dine using a function which has a return type as integer.​

Answers

Answered by samarthkrv
1

Answer:

import java.lang.Math;

public class Main

{

   static int len(int n){

       int len = 0;

       while(n!=0){

           len++;

           n/=10;

       }

       return len;

   }

   static double sum(int n){

       double sum = 0;

       final int l = len(n);

       while(n!=0){

           int r = n%10;

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

           n/=10;

       }

       return sum;

   }

public static void main(String[] args) {

 System.out.println(sum(1234));

}

}

Explanation:

Similar questions
English, 22 hours ago