完全数 要求输入1到1000之间的的任何一个数说出是不是完全数,并要求把他分开输出。例如:6是完全数,6=1+2+3; 28是完全数 28=1+2+4+7+14;多谢大家的指点是要一个带方法的程序。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class T { public static void main(String args[]){ for(int i=1; i<10000; i++){ if(test(i)){ System.out.println(i); } } } public static boolean test(int it){ int tmp=0; for(int i=1; i<it; i++){ if(it%i == 0){ tmp += i; } } if(tmp==it){ return true; } else return false; }} import java.util.*;public class T { public static void main(String args[]){ for(int i=1; i<10000; i++){ test(i); } } public static void test(int it){ int tmp=0; ArrayList<Integer> list = new ArrayList<Integer>(); for(int i=1; i<it; i++){ if(it%i == 0){ tmp += i; list.add(new Integer(i)); } } if(tmp==it){ Iterator ite = list.iterator(); System.out.print(it+"="); while(ite.hasNext()){ System.out.print("+"+(Integer)ite.next()); } System.out.println(";"); } }} ArrayList<Integer> list = new ArrayList<Integer>()-----------------------这是5.0里面的写法吧,现在5.0都开始流行了哦 Object转int数组 关于变量赋值 log4j有没有读取log的方法?因为文件很大,最好不要一次都读进内存再解析的哪种. 急!(望高手指点迷津) java桌面程序开发的前景是否乐观? 如何把JAR 文件 制成EXE文件 如何生成一个二叉树 如何对Jtree某一个节点下的内容排序? 每次更新环境变量后,都需要重启,很是麻烦,有没有办法不要重启 问个SQL server的jdbc连接的问题. 这个问题好难! JBuilder2005 通过Microsoft SQL Server 2000 Driver for JDBC 连接Microsoft SQL Server 2000 的配置问题,急啊
public static void main(String args[]){
for(int i=1; i<10000; i++){
if(test(i)){
System.out.println(i);
}
}
}
public static boolean test(int it){
int tmp=0;
for(int i=1; i<it; i++){
if(it%i == 0){
tmp += i;
}
}
if(tmp==it){
return true;
}
else
return false;
}
}
public static void main(String args[]){
for(int i=1; i<10000; i++){
test(i);
}
}
public static void test(int it){
int tmp=0;
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=1; i<it; i++){
if(it%i == 0){
tmp += i;
list.add(new Integer(i));
}
}
if(tmp==it){
Iterator ite = list.iterator();
System.out.print(it+"=");
while(ite.hasNext()){
System.out.print("+"+(Integer)ite.next());
}
System.out.println(";");
}
}
}
-----------------------
这是5.0里面的写法吧,现在5.0都开始流行了哦