forked from BimalRajGyawali/hacktoberfest-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDudeneyNumber.java
34 lines (31 loc) · 947 Bytes
/
DudeneyNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner;
public class DudeneyNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = in.nextInt();
//Check if n is a perfect cube
int cubeRoot = (int)Math.round(Math.cbrt(n));
if (cubeRoot * cubeRoot * cubeRoot == n) {
//If n is perfect cube then find
//sum of its digits
int s = 0;
int t = n;
while (t != 0) {
int d = t % 10;
s += d;
t /= 10;
}
if (s == cubeRoot) {
System.out.println(n + " is a Dudeney number");
}
else {
System.out.println(n + " is not a Dudeney number");
}
}
else {
System.out.println(n + " is not a Dudeney number");
}
}
}