Perfect Number

import 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!

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!