Skip to content

Instantly share code, notes, and snippets.

@peter279k
Last active May 24, 2017 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/6965a3146253c2aa1a6d9c412dd09b4c to your computer and use it in GitHub Desktop.
Save peter279k/6965a3146253c2aa1a6d9c412dd09b4c to your computer and use it in GitHub Desktop.
TQC+ JAVA
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