---
title: "完全数的java代码"
author: "duyunfengsolo"
date: "2009-12-14T14:28:14Z"
tags: []
categories: ["非技术"]
slug: "java"
draft: false
lastmod: "2009-12-15T14:17:09Z"
id: 548088
url: "https://solodu.iteye.com/blog/548088"
---

求1到100000之间的所有的“完全数”，好像是叫“完全数”，总之像这样的就是了。

例如6=1+2+3; 2和3都是6的因数。还有28也是：28=1+2+4+7+14;

就像上面的那样。

代码如下：

```
package com;

import java.util.ArrayList;
import java.util.List;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Test t = new Test();
		t.aa();
	}
	
	public void aa(){
		List<Integer> list = new ArrayList<Integer>();
		long t1 = System.currentTimeMillis();
		for(int i=2;i<100000;i++){
			list.clear();
			int temp = i;
			for(int j=2;j<i;j++){
				if(i % j == 0){
					list.add(j);
				}
			}
			int temp2 = 0;
			for(int m=0;m<list.size();m++){
				temp2 = temp2 + list.get(m);
			}
			if(temp == temp2+1){
				System.out.println("temp="+temp);
				long t2 = System.currentTimeMillis();
				System.out.println("time=" + (t2 - t1)); 
			}
		}
	}

}
```