This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Java in General and the fly likes BigInteger: strange problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "BigInteger: strange problem" Watch "BigInteger: strange problem" New topic
Author

BigInteger: strange problem

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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


SCJP
Visit my download page
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

never mind. this is the second time i made this mistake.
should be count = count.add(quotient);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BigInteger: strange problem