Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 too big for BigInteger
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zylum




PostPosted: Mon Jun 26, 2006 6:27 pm   Post subject: (No subject)

for(int i = 1; i <= 317584931803; i++){


317584931803 isnt exactly an integer... how is i, which is an integer type, supposed to go all the way up to that?
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Mon Jun 26, 2006 6:32 pm   Post subject: (No subject)

even if i decrease the number it still says incompatible types. try it
HellblazerX




PostPosted: Mon Jun 26, 2006 7:35 pm   Post subject: (No subject)

You just forgot to do any comparing inside that if statement. You called compareTo (), but you never actually used or compared the value that it returned, so that's why its giving you that error.
code:
if (num.mod(BigInteger.valueOf(i)).compareTo(BigInteger.ZERO) == 0) {

And zylum's right. That number is too big for an int. Why not use BigIntegers instead in the for loop?
cool dude




PostPosted: Mon Jun 26, 2006 8:32 pm   Post subject: (No subject)

thanks. the thing that i don't understand is that when u say:

code:

compareTo(BigInteger.ZERO)


doesn't that compare to zero already? why do u need to restate == 0 if it already compares it to zero Confused
wtd




PostPosted: Mon Jun 26, 2006 9:55 pm   Post subject: (No subject)

Look up the documentation for compareTo.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html
cool dude




PostPosted: Tue Jun 27, 2006 8:26 pm   Post subject: (No subject)

i'm trying to make my counted loop be able to go to a huge number, thus i am trying to use BigInteger again. i dunno why but BigInteger just doesn't seem to stick to my head Confused if anyone could make a tutorial that would be great. i tried doing the counted loop but it says:
Quote:
operator < cannot be applied to BigInteger


code:

for(int i = 1; (num.compareTo(BigInteger.valueOf(i)) < num) ; i++){
wtd




PostPosted: Tue Jun 27, 2006 10:49 pm   Post subject: (No subject)

Java objects do not support operator overloading.

Have you tried reading through a basic introduction to Java, to get a grasp on the fundamentals? I ask because the things you keep encountering problems with are pretty basic.
cool dude




PostPosted: Wed Jun 28, 2006 7:42 pm   Post subject: (No subject)

wtd wrote:
Java objects do not support operator overloading.

Have you tried reading through a basic introduction to Java, to get a grasp on the fundamentals? I ask because the things you keep encountering problems with are pretty basic.


i did read through the beginning parts so far. then it gets a lot more complicated and i want to practice this stuff before i move on to make sure i fully understand it. also no where in your tutorial did you explain how to use BigIntegers. also i still don't understand how i would make a counted loop to go up to such a large number?
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Jun 28, 2006 10:38 pm   Post subject: (No subject)

cool dude wrote:
also no where in your tutorial did you explain how to use BigIntegers.


For very good reason.

There are 3000+ classes. If I tried to write tutorials for all of them, I'd die of old age before finishing. What I can do is explain the way objects and classes work, and the rules they play by. Then, knowing that, you can figure out the classes you need to use.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 24 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: