Program to determine if a no. Is a perfect no. Or not | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Program to determine if a no. Is a perfect no. Or not

hi guys this weekend I was free so I wanted to create a program in Java to determine whether a no. is perfect or not but I can't make that for this I have created a program to take out the factors of the input No. u can take the help of that and in case u don't know what is a perfect no.then it is a no. whose sum of factors is equal to the no. like 6=1x2x3 and 6=1+2+3 any answer will be appreciated

19th Mar 2017, 3:23 AM
niraj srivastava
niraj srivastava - avatar
2 Answers
+ 5
int number, factor = 0; // Code to get number for(int x = 1; x < number; x++) { if(number % x == 0) { factor += x; } } if(factor == number) { System.out.println("Perfect number!"); } else { System.out.println("Not perfect."); }
19th Mar 2017, 4:17 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thanks
19th Mar 2017, 6:26 AM
niraj srivastava
niraj srivastava - avatar