java程序 求階乘和
import ner;
/**
* 求正整數階乘和
*/
public class $sum {
@SuppressWarnings("resource")
public static void main(String[] args) {
//控制檯輸入階乘的最大值:
Scanner sc=new Scanner();
tln("Input Number:");
long input=Int();
//定義變量:
long temp=1;
long sum=0;
String newsum = "";
//循環主體內容
for(int i=0;i
for(int k=1;k<=i+1;k++)
tln((i+1)+"!="+temp+" ");//打印1-n的各自的階乘數
sum=sum+temp;//求和
//求各自階乘的String
if(i+1==input){
newsum=newsum+(i+1)+"!";
}else{
newsum=newsum+(i+1)+"!+";
}
//重置臨時變量temp
temp=1;
}
tln("");//換行
tln(newsum+"="+sum);//輸出結果
}
}