Forums Register Login

BigIntegers...

+Pie Number of slices to send: Send
I've spent over an hour on this.

I'm trying to add two BigIntegers and have some kind of knot somewhere. Can someone please help me add 1 + 1 using the BitInteger Object, then add A third one to the result of 1 + 1?

I feel so dumb.
+Pie Number of slices to send: Send
Instances of BigInteger are objects, so regular numeric operators won't work. Instead, you call methods, defined in the API...

http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigInteger.html

For example, to add existing BigInteger instances b1 and b2, then assign the result to b3, you could do the following...

BigInteger b3 = b1.add(b2);

Note that the sum is returned by the method, which does not change the values of b1 or b2.

Also note that "1" is a special constant, so you don't need to create your own instance. You can simply use BigInteger.ONE.
[ February 18, 2005: Message edited by: marc weber ]
+Pie Number of slices to send: Send
Here you can find "short code samples" for operations whic involve BigIntegers :

Java Almanac

Also try to search for other "code samples" before posting your question here, I found many answers there. I hope it will help you

kind regards
Igor
+Pie Number of slices to send: Send
Thanks.

If I hadn't spent the time on it, I wouldn't have asked. I usually search here and Google befor I come for assistance.
+Pie Number of slices to send: Send
I am not sure if You did actually read information provided by that link since its very straightforward and as i can see you have sun certificate so I asume you should be able to get your code working from this example which is provided by above link




kind regards
Igor
+Pie Number of slices to send: Send
You are a certified SCJP and you don't know how to look up this information in the Java API documentation? That just scares me...

Layne
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1204 times.
Similar Threads
sum of two int arrays
Effective Java 2nd Edition - item 15
Finding the largest Prime Factor
BigInterger math and conversions
API Test question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:28:35.