How to find a number is Perfect Number or Not

How to find a number is Perfect Number or Not
SOURCE : PerfectNo.java

public class PerfectNo {
public static void main(String[] args) {
PerfectNo pf = new PerfectNo();
pf.pfnum(6);

}

int temp = 0;

private void pfnum(int num) {
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
temp += i;
}
}
if (temp == num) {

System.out.println("number is perfect");
} else {
System.out.println("number is not perfect");
}

}

}

INPUT

6



OUTPUT

number is perfect






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment