Does BigInteger
only have equals
for comparison?
Are there substitutes for math notation like < (greater than) or < (less than)?
^Answered!
now i want to know, is there a way using BigInteger
in iteration such as while
and for
?
Does BigInteger
only have equals
for comparison?
Are there substitutes for math notation like < (greater than) or < (less than)?
^Answered!
now i want to know, is there a way using BigInteger
in iteration such as while
and for
?
You can't use math notation, in fact I wouldn't get in the habit of using == either, I'm fairly sure that unless they used some serious trickery it will fail.
a = new BigInteger(500);
b = a;
if( a == b )
will always be true
b=new BigInteger(500);
if( a == b )
will never be true
if( a.equals(b) )
will always work fine.
Java isn't a great language for this kind of stuff--I really love Java but ended up having a lot of trouble implementing a Complex class and then implementing a matrix that could hold and manipulate the complex class.
My solution was to use Java to create the core classes then use Groovy to create the classes that used the core classes. If you follow certain naming patterns, then you can use any operators on any class.
Or if you just want to mess with big numbers simply use groovy and don't even declare a type for your variables--it will automatically promote them to whatever you need.
You can use the compareTo method.