public static void main(String... _) throws Throwable {
int MAX = 10;
StringBuilder result = new StringBuilder();
result.append(MAX).append("!=");
int fac = 1;
for(int i = 1; i <= MAX; i++) {
fac *= i;
result.append(i);
if(i < MAX) {
result.append('*');
}
}
result.append('=').append(fac);
System.out.println(result.toString());
}
public static void main(String... _) throws Throwable {
int MAX = 10;
String result = MAX + "!=";
int fac = 1;
for(int i = 1; i <= MAX; i++) {
fac *= i;
result += i;
if(i < MAX) {
result += '*';
}
}
result = result + '=' +fac;
System.out.println(result);
}
public static void main(String... _) throws Throwable {
int MAX = 10;
// rechne
int fac = 1;
for(int i = 1; i <= MAX; i++) {
fac *= i;
}
// bastle String zusammen
String result = MAX + "!=";
for(int i = 0; i <=MAX ;i ++) {
result += i;
if(i < MAX) {
result += '*';
}
}
result = result + '=' +fac;
// ausgeben
System.out.println(result);
}
/**
* Funktion zur Berechnung der Fakultät
*
* @param pValue
* Zahl
* @return <b>BigDecimal</b> Fakultät der Zahl
*/
public static BigDecimal faculty(BigDecimal pValue) {
BigDecimal tValue = pValue;
BigDecimal tBig = pValue;
if (pValue.equals(0)) {
return BigDecimal.ONE;
}
while (pValue.longValue() > 1) {
tBig = tBig.multiply(tValue = tValue.subtract(BigDecimal.ONE));
}
return tBig;
}
/**
* Funktion zur Berechnung der Fakultät
*
* @param pValue
* Zahl
* @return <b>BigDecimal</b> Fakultät der Zahl
*/
public static BigDecimal faculty(long pValue) {
return faculty(BigDecimal.valueOf(pValue));
}
int val = 42;
BigDecimal big = BigMath.faculty(val);
System.out.println(val + "! = " + big);
42! = 1405006117752879898543142606244511569936384000000000
import static org.birpn.BIRPN.*;
...
BigInteger s = _("42 !");
...