Java implementation to find out all the numbers within 1000

Source: Internet
Author: User

/** *  * title: If a number is exactly equal to the sum of its factors, this number is called the "end number". For example, 6=1+2+3. Programming   Finding out all the ends within 1000  * */public class Test9 {     Public static int perfact (int n)  {        int  s = 0;        for  (int i = 1;i  <= n / 2;i++)  {             if  (n % i == 0)  {                 s = s+i;             }        }         if  (s == n)  return 1;         Return 0;    }    public static&nbsP;void main (String[] args)  {        for  (int  i=1;i<=1000;i++)  {            if (Perfact (i )  == 1)  {                 system.out.println (i);             }         }    }}


This article is from the "Orange Growth Record" blog, be sure to keep this source http://azhome.blog.51cto.com/9306775/1546774

Java implementation to find out all the numbers within 1000

Related Article

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.