in assignment 1.6: I can create the list, and the final number for square 64 is -9223372036854775808 So I am assuming I need to use the BigInteger class from the java.math.* package to get rid of that "-". I have tried various combinations but to no avail. For example I tried using the method valueOf(long val) as follows: public static BigInteger valueOf(long x) { return x; }; in my "Grains" class and got the reply: "Incompatible type for return. can't convert long to java.math.BigInteger." which is what I thought this method was for! I also looked at the pow(int exponent) method which looks like it could do all the work except that I too am lost with the "this" part. Can someone point me on the right track? Have I even chosen the right package?! thanks, Richard

If you want to use the BigInteger class you need to create an instance of it. Example: BigInteger bi = new BigInteger Then use the methods of BigInteger on that object.

Anxiety does not empty tomorrow of its sorrows, but only empties today of its strength. – Charles Spurgeon

In this case valueOf is a static method if BigInteger, so no instance is necessary. Richard- if I understand what you're asking and doing, then you're creating your own definition of valueOf. This is unnecessary as the method is already defined in BigInteger to do what you want. You can use it like this: <pre> BigInteger bi = BigInteger.valueOf(someValue);</pre> where someValue can be any integral type (it will be implicitly converted to long if necessary).

"I'm not back." - Bill Harding, Twister

Richard Gibson
Greenhorn

Joined: Mar 16, 2000
Posts: 9

posted

0

I have managed to get BigInteger to work in the following code:

STUFF DELETED which works (i.e. it compiles), but the result is still the -9.... number above. Is the problem that I need to do my multiplications directly with BigInteger. I tried the bi = (bi * 2) and, of course, got the message that BigInteger is NOT an int. R

[This message has been edited by Paul Wheaton (edited March 21, 2000).]