# BigInteger: strange problem

posted 4 years ago

i finally found a formula for solving euler116. it worked fine using longs and a smaller input but i had to change to BigInteger. the result is strange. i have these lines of code

BigInteger count = BigInteger.ZERO;

BigInteger quotient = num.divide(den);

System.out.println(quotient);

count.add(quotient);

System.out.println(count);

it prints out (for example)

9

0

how is this possible???

if quotient is 9 and count starts out being 0 it should print out 9!!!

i can post entire code if necessary

BigInteger count = BigInteger.ZERO;

BigInteger quotient = num.divide(den);

System.out.println(quotient);

count.add(quotient);

System.out.println(count);

it prints out (for example)

9

0

how is this possible???

if quotient is 9 and count starts out being 0 it should print out 9!!!

i can post entire code if necessary

SCJP

Visit my download page

posted 4 years ago

here is entire code

it prints out

362880

40320

9

0

40320

1440

28

0

5040

144

35

0

720

48

15

0

120

120

1

0

it prints out

362880

40320

9

0

40320

1440

28

0

5040

144

35

0

720

48

15

0

120

120

1

0

SCJP

Visit my download page

posted 4 years ago

- 1

never mind. this is the second time i made this mistake.

should be count = count.add(quotient);

should be count = count.add(quotient);

SCJP

Visit my download page