Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- public class FactorialTest {
- private static final NumberFormat formatter = new DecimalFormat("#");
- public static void main(String[] args) {
- double fact = 1;
- BigInteger bigFact = new BigInteger("1");
- int i = 0;
- do {
- i++;
- fact *= i;
- bigFact = bigFact.multiply(new BigInteger(String.valueOf(i)));
- final String bigFormat = bigFact.toString();
- System.out.println(i + " = " + bigFormat);
- final String doubleFormat = formatter.format(fact);
- if (!doubleFormat.equals(bigFormat)) {
- System.out.println(" != " + doubleFormat);
- }
- } while (i < 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement