Thu Sep 09 2021
Perfect Number
Java Programming1313 views
File Name: perfect-number.java
aimport java.io.*;
class checking {
/* Constructor of the class */
checking(int no) {
int i = 1, sum = 0;
while(i < no) {
if(no % i == 0)
sum += i;
i++;
}
if(sum == no)
System.out.println("It's a Perfect Number!");
else
System.out.println("It's not a Perfect Number!");
}
}
class perfectno {
public static void main(String args[]) {
int number = Integer.parseInt(args[0]);
checking perfect = new checking(number);
}
}
/* Output */
java perfectno 6
It's a Perfect Number!
/* ------------------------- */
java perfectno 8
It's not a Perfect Number!
Reference:
Author:Geekboots