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 !!!