Skip to content

Instantly share code, notes, and snippets.

@peter279k peter279k/JPA03.java
Last active May 24, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.