Last active
May 24, 2017 10:47
-
-
Save peter279k/6965a3146253c2aa1a6d9c412dd09b4c to your computer and use it in GitHub Desktop.
TQC+ JAVA
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
import java.util.Scanner; | |
public class JPA03 { | |
public static void main(String[] args) { | |
int i, num, sum = 0; | |
System.out.printf("1~1000中的完美數有: "); | |
for(i=1;i<=1000;i++) { | |
num = i; | |
sum = 0; | |
for(int j=1;j<i;j++) { | |
if(i % j == 0) { | |
sum += j; | |
} | |
} | |
if(sum == num) { | |
System.out.printf("%d ",num); | |
} | |
} | |
System.out.printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment