AlgorithmGossip完美數簡版
阿新 • • 發佈:2019-02-09
public class Algorithm_Gossip {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("輸入一個數字");
PerfectNumber(input.nextInt());
input.close();
}
public static void isPerfectNumber(int number){
int sum = 0;
for(int i = 1; i< number;i++ ){
if(number % i ==0){
sum+= i;
}
}
if(sum == number){
System.out.println(number + "是完美數");
}
}
public static void PerfectNumber(int number){
for(int i = 1; i<= number; i++){
isPerfectNumber(i);
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("輸入一個數字");
PerfectNumber(input.nextInt());
input.close();
}
public static void isPerfectNumber(int number){
int sum = 0;
for(int i = 1; i< number;i++ ){
if(number % i ==0){
sum+= i;
}
}
if(sum == number){
System.out.println(number + "是完美數");
}
}
public static void PerfectNumber(int number){
for(int i = 1; i<= number; i++){
isPerfectNumber(i);
}
}
}