Perfect Number

Java Programming

Java Programming Examples

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!

Learn more about Perfect Number