Created
May 1, 2014 06:23
-
-
Save ssd863419/9cd89235c7595498fcb7 to your computer and use it in GitHub Desktop.
列出水仙花數
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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