public class Test1 { public static void main(String args[]) { long a, u, b; u = 1; b = 0; String str = null; for (a = 1; a <= 20; a++) { u = u * a; b = b + u; if (a == 1) { str = a + "!"; } else { str = str + "+" + a + "!"; } System.out.println(str + "=" + b); } } }
import java.math.BigInteger; public class Big {
public static BigInteger sum = new BigInteger("0"); public static BigInteger ml_value = null; public static BigInteger temp = null; public static String s = null; public static void mul(int n) { ml_value = new BigInteger("1");
for(int i =2 ;i<n+1;i++) { s = String.valueOf(i); temp = new BigInteger(s); ml_value = ml_value.multiply(temp); } } public static void main (String args[]) { int num = Integer.parseInt(args[0]); for(int j = 1; j <= num; j++) { mul(j); sum = sum.add(ml_value); } System.out.println(sum.toString()); } }
public class TestFactorial { public static void main(String[] args) { int sum = 0; for(int i=1; i<21; i++) { sum = sum + calculate(i); } System.out.println(sum);
}
public static int calculate(int num) { if(num == 1) { return 1; } return calculate(num - 1)*num; } }
public class Test1 { public static void main(String args[]) {
long a, u, b;
u = 1;
b = 0;
String str = null;
for (a = 1; a <= 20; a++) {
u = u * a;
b = b + u;
if (a == 1) {
str = a + "!";
} else {
str = str + "+" + a + "!";
}
System.out.println(str + "=" + b);
} }
}
import java.math.BigInteger;
public class Big
{
public static BigInteger sum = new BigInteger("0");
public static BigInteger ml_value = null;
public static BigInteger temp = null;
public static String s = null;
public static void mul(int n)
{
ml_value = new BigInteger("1");
for(int i =2 ;i<n+1;i++)
{
s = String.valueOf(i);
temp = new BigInteger(s);
ml_value = ml_value.multiply(temp);
} }
public static void main (String args[])
{
int num = Integer.parseInt(args[0]);
for(int j = 1; j <= num; j++)
{
mul(j);
sum = sum.add(ml_value);
}
System.out.println(sum.toString());
}
}
public class TestFactorial
{
public static void main(String[] args)
{
int sum = 0;
for(int i=1; i<21; i++) {
sum = sum + calculate(i);
}
System.out.println(sum);
}
public static int calculate(int num) {
if(num == 1) {
return 1;
}
return calculate(num - 1)*num;
}
}
呵呵,满足LZ需要了;不过为n的时候(如n>1000),可能就要越界了,用StringBuffer是最好的。