import java.util.Scanner;
public class Dudeney {
public static void main(String[] args) {
NumDude obj = new NumDude();
obj.input();
obj.isDude();
}
}
class NumDude {
public void isDude() {
if (numb == (int) Math.pow(sumDigits(numb), 3)) {
System.out.println(numb + " is a Dudeney Number");
}else {
System.out.println(numb + " is not a Dudeney Number");
}
}
private int sumDigits(int x) {
if (x > 10) {
return ((x % 10) + sumDigits(x / 10));
} else {
return x;
}
}
public void input() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a positive integer: ");
numb = scanner.nextInt();
scanner.close();
}
public NumDude() {
this.numb = 0;
}
private int numb;
}
🔢 Dudeney Number Checker
A Dudeney number is a positive integer that is a perfect cube such that the sum of its decimal digits equals the cube root of the number.
🎯 Examples:
- 1 = 1³ and 1 = 1
- 512 = 8³ and 5+1+2 = 8
- 4913 = 17³ and 4+9+1+3 = 17
- 5832 = 18³ and 5+8+3+2 = 18
Try numbers like: 1, 512, 4913, 5832, 17576, 19683
No comments:
Post a Comment