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
0

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 int sum(int n){

       int sum = 0;

       int l = len(n);

       int temp = n;

           while(temp!=0){

               int r = temp%10;

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

               temp/=10;

           }

       return sum;

   }

public static void main(String[] args) {

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

}

}

Explanation:

Similar questions