/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package l_fifty.seven_eleven;
/**
*
* @author lonely
*/
public class L_fiftySeven_eleven {
/**
* 计算1^1+2^2+3^3……20^20
*/
public static void main(String[] args) {
// TODO code application logic here
double sum=0.0d;//因为结果超出了长整数的表示范围,故用long
for(int i=1;i<=20;i++)
{
double s=1;
for(int j=0;j<i;j++)
{
s*=i;//求次幂
}
sum+=s;//求和
}//for循环结束
System.out.println(sum);
}//main结束
}//类结束
Java结构化程序设计2
最新推荐文章于 2022-09-30 23:42:35 发布