How to print perfect numbers from 1 to 100 in Java?
public class factors public static void main(String args[]) int sum=0; for(int k=2;k<=30;k++) for(int i=1;i<k;i++) if(k%i==0) sum=sum+i; if(k==sum) System. out. println(sum); sum=0; //sum=0 is very important.
What are the perfect numbers between 1 and 1000?
Around 100 c.e., Nicomachus noted that perfect numbers strike a harmony between the extremes of excess and deficiency (as when the sum of a number's divisors is too large or small), and fall in the “suitable” order: 6, 28, 496, and 8128 are the only perfect numbers in the intervals between 1, 10, 100, 1000, 10000, and ...