Java startup -- evaluate the full number

Source: Internet
Author: User

112 people read comments (0) collect reports
/*
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File Name:
* Author: Zhang chuanxin
* Completion date: January 1, September 22, 2012
* Version No.: J.1.04
* Description of tasks and Solutions
* Input description:
* Problem description: if a natural number is used, the sum of all its true factors (that is, an approximate number other than itself) exactly equals to itself. This number is called a complete number. Summary"
For example,
6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248
8128 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064
* Program output: Write a Java program that outputs all the final numbers between any numbers.
* Problem Analysis: to calculate the number of input records of a number, the sum of the divisor values of this number must be equal to itself.
* Algorithm Design: first, define the function to calculate the approximate number of the desired number, then add the approximate number, and compare it with itself to determine the result...
*/
[Java]
<Span style = "font-size: 14px;">
Public class TestComNum {
 
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
PrintComNum (1000 );
}
Static void printComNum (int n ){
For (int I = 1; I <= n; I ++ ){
Int s = 0;
For (int j = 1; j <I; j ++ ){
If (I % j = 0 ){
S = s + j;
}
}
If (s = I ){
System. out. println (I + "is a full number ...");
}
}
}
} </Span>
Running result:
6 is the full number...
28 is a full number...
496 is a full number...

Experience Accumulation: from now on, it has become a good habit. Don't be busy coding. It is more important to analyze problems and build a framework !!!

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.