请教高手!(30分) 这类问题太多了.使用BigInteger类来计算.这个类使用很简单,查看一下api帮助文档吧. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Math.pow(n,n) 求和后判断是否超出了long的表示范围,可用double 二楼说的应该对吧,如果超出long,怎么循环递归也没用啊,楼上好像理解错了 初学JAVA,水平不够。能给出原代码吗? 回复人: yulin001122() ( ) 信誉:100 2005-04-13 16:32:00 得分: 0 楼上的有没有学过计算机啊受不了了。。======================================================================你什么意思?说我吗?学过几天计算机就了不起了?你有本事用double算出这题的精确答案出来!假如要算到200呢?doubule还能算吗?使用biginteger的代码如下:import java.math.BigInteger;public class Power { public static String calculateBigInteger(int max){ if(max <= 0){ return "输入参数错误!"; } BigInteger ret = new BigInteger("1"); for(int i=2; i<=max; i++){ BigInteger current = new BigInteger(Integer.toString(i)); ret = ret.add(current.pow(i)); } return ret.toString(); } public static void main(String[] args){ System.out.println(Power.calculateBigInteger(20)); }}答案为:106876212200059554303215024 我不是说你 我说要用DOUBLE那些人 回复人: yulin001122() ( ) 信誉:100 2005-04-14 15:14:00 得分: 0 我不是说你 我说要用DOUBLE那些人 ======================================================呵呵,误会.不过也不能说"有没有学过计算机啊",特别是象我这种没有学过计算机的人,比较敏感的:) java工作 双链表问题 myeclipse 图形插件在哪下啊 问个线程同步的问题 提示一条错误,但能运行,不知道是怎么回事啊 Java程序可不可以嵌入flash 关于接口的一段话如何理解? 求proxy小程序 在什么系统下学习比较好? jdbc 问题,救我!!!!!!!!!!! 如何获得当前session的总数 JSP的入门问题,高手赐教
如果超出long,怎么循环递归也没用啊,楼上好像理解错了
能给出原代码吗?
楼上的有没有学过计算机啊
受不了了。。
======================================================================
你什么意思?说我吗?学过几天计算机就了不起了?
你有本事用double算出这题的精确答案出来!
假如要算到200呢?doubule还能算吗?使用biginteger的代码如下:import java.math.BigInteger;public class Power {
public static String calculateBigInteger(int max){
if(max <= 0){
return "输入参数错误!";
}
BigInteger ret = new BigInteger("1");
for(int i=2; i<=max; i++){
BigInteger current = new BigInteger(Integer.toString(i));
ret = ret.add(current.pow(i));
}
return ret.toString();
} public static void main(String[] args){
System.out.println(Power.calculateBigInteger(20));
}
}答案为:106876212200059554303215024
我说要用DOUBLE那些人
我不是说你
我说要用DOUBLE那些人
======================================================
呵呵,误会.
不过也不能说"有没有学过计算机啊",特别是象我这种没有学过计算机的人,比较敏感的:)