注:int型已经无法存储,需要定义long型变量
Jiecheng.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
public class Jiecheng {
public void print(){
int number=20;
long sum=1L;
long k=1l;
for(int i=1;i<=number;i++){
k=k*i;
sum=sum+k;
}
System.out.println(sum-1);
}
}
Test.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
public class Test {
public static void main(String[] args){
Jiecheng jc=new Jiecheng();
jc.print();
}
}