mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-19 01:41:57 +08:00
@ -10,7 +10,7 @@ import java.io.*;
|
||||
|
||||
public class DudeneyNumber {
|
||||
|
||||
//returns True if the number is a Dudeney number and False if it is not a Dudeney number.
|
||||
// returns True if the number is a Dudeney number and False if it is not a Dudeney number.
|
||||
public static boolean isDudeney(int n) {
|
||||
// Calculating Cube Root
|
||||
int cube_root = (int) (Math.round((Math.pow(n, 1.0 / 3.0))));
|
||||
@ -19,7 +19,7 @@ public class DudeneyNumber {
|
||||
return false;
|
||||
}
|
||||
int sum_of_digits = 0; // Stores the sums of the digit of the entered number
|
||||
int temp = n; //A temporary variable to store the entered number
|
||||
int temp = n; // A temporary variable to store the entered number
|
||||
// Loop to calculate sum of the digits.
|
||||
while (temp > 0) {
|
||||
// Extracting Last digit of the number
|
||||
@ -32,7 +32,7 @@ public class DudeneyNumber {
|
||||
temp /= 10;
|
||||
}
|
||||
|
||||
//If the cube root of the number is not equal to the sum of its digits we return false.
|
||||
// If the cube root of the number is not equal to the sum of its digits we return false.
|
||||
return cube_root == sum_of_digits;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user