/ * * If a natural number, all its true factors (that is, other than its own approximate) and exactly equal to itself, this number is called the complete number, short-end number. * For example: 6=1+2+3. * Title: Please complete the number within 1000. */public class Perfectnumber {//number upper limit static Integer limit = 1000;public static void Main (string[] args) {System.out.printl N (limit + "complete number within:"); fun (limit);} public static void Funny (Integer limit) {for (int i = 1; I <= limit; i++) {//define TRUE factor sum variable int sum = 0;for (int j = 1; J < I/2 + 1; J + +) {//If the current number can be divisible if (i% J = = 0) {sum + = j;}} If the true factor (that is, an approximate number other than itself) is exactly equal to itself, the description is complete. if (sum = = i) {System.out.println (i);}}}}
Output Result:
the total number within 1000 is:628496
The Java version of the total number of 1000 or less