The Java version of the total number of 1000 or less

Source: Internet
Author: User
/  * * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.