Skip to content

Instantly share code, notes, and snippets.

@ssd863419
Created May 1, 2014 06:23
Show Gist options
  • Save ssd863419/9cd89235c7595498fcb7 to your computer and use it in GitHub Desktop.
Save ssd863419/9cd89235c7595498fcb7 to your computer and use it in GitHub Desktop.
列出水仙花數
public class Test {
public static boolean isDaffodils(int inPut){
int a1 = inPut % 10 ; //個位
int a2 = ( inPut / 10 ) % 10 ; //十位
int a3 = inPut /100 ;//百位
double sum = Math.pow(a1,3) + Math.pow(a2,3) + Math.pow(a3,3);
if (inPut == sum) {
return true;
}
return false;
}
public static void main(String[] args) {
for (int i = 100; i < 1000; i++) {
if (isDaffodils(i)) {
System.out.print(i + ",");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment