import java.util.*;
public class code{
public static void main(String argv[]) {
Scanner scanner = new Scanner(System.in);
int i, num, sum = 0;
System.out.println("歡迎使用【新版完美數計算器】- ★作者 : 張健勳");
System.out.println("《系統》程式已讀取完畢");
System.out.println("");
System.out.printf("《提醒》請輸入最小值:");
int x=scanner.nextInt();
System.out.printf("《提醒》請輸入最大值:");
int y=scanner.nextInt();
System.out.println("");
System.out.println("《系統》計算中請稍後");
System.out.println("");
System.out.println("");
System.out.printf("《計算結果》"+x+"~"+y+"中的完美數有: ");
for (i=x ;i<=y; i++){
sum=0;
for (num=1 ;num<i ;num++) {
if (i % num == 0)sum += num;
}
if (i == sum) {
System.out.printf("%d ",num);
}
}
System.out.printf("\n");
}
} |