使用while单循环求1!+2!+3!+...+6!+7!
1、
public class Test33{ public static void main(String[]args){
int i=1;
int j=1;
int sum=0;
while (i<=7) {
j=j*i;
i++;
sum=sum+j;//1*1+1*1*2+1*1*2*3....
} System.out.println(sum); } }
2、
public class Test3{
public static void main(String[] args){
int i = 1;
int j = 1;
int sum = 0;
//--每个数阶乘的和
int jc = 1;
/* sum = 1*1+1*2+1*2*3+1*2*3*4...... */
while(i<=7){
//--单独的每个数的阶乘和
while(j<=i){
jc = jc*j;
j++;
}
i++;
sum = sum + jc;
} System.out.println("sum:"+sum);
} }