Dudeney Numbers | Java implementation of the approach ; Function that returns true if n is a Dudeney number ; If n is not a perfect cube ; Last digit ; Update the digit sum ; Remove the last digit ; If cube root of n is not equal to the sum of its digits ; Driver code
import java . lang . Math ; class GFG { static boolean isDudeney ( int n ) { int cube_rt = ( int ) ( Math . round ( ( Math . pow ( n , 1.0 / 3.0 ) ) ) ) ; if ( cube_rt * cube_rt * cube_rt != n ) return false ; int dig_sum = 0 ; int temp = n ; while ( temp > 0 ) { int rem = temp % 10 ; dig_sum += rem ; temp /= 10 ; } if ( cube_rt != dig_sum ) return false ; return true ; } public static void main ( String [ ] args ) { int n = 17576 ; if ( isDudeney ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }