Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By JosAH

Thread: Problem getting biginteger to work

  1. #1
    Sulfuri is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Problem getting biginteger to work

    I want to do this with bigintegers
    Java Code:
     if(MaxNum%x == 0)
    note that MaxNum is a big integer and x is just a regular integer.
    I tried writing
    Java Code:
    if(MaxNum.mod(x) == 0)
    but the compiler tells me to convert x to a big integer which I rather avoid if possible.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default Re: Problem getting biginteger to work

    All calculation methods in BigInteger class require you to use BigInteger as the parameter. These methods like add(), mod(), multiply(), divide(), etc. There's no overload that I can see that accept integer. So you have to convert it. You can do by using BigInteger.valueOf(x).

  3. #3
    Sulfuri is offline Member
    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Default Re: Problem getting biginteger to work

    Quote Originally Posted by wsaryada View Post
    All calculation methods in BigInteger class require you to use BigInteger as the parameter. These methods like add(), mod(), multiply(), divide(), etc. There's no overload that I can see that accept integer. So you have to convert it. You can do by using BigInteger.valueOf(x).
    Do you mean for it to be like this?
    Java Code:
    if(MaxNum.mod(BigInteger.valueOf(x)) == Zero)
    Where "Zero" is:
    Java Code:
     BigInteger Zero= new BigInteger ("0");
    For some reason this just freezes my program. I get no error.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,345
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem getting biginteger to work

    Do this instead:

    Java Code:
    if(MaxNum.mod(BigInteger.valueOf(x)).equals(BigInteger.ZERO))
    kind regards,

    Jos
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 0
    Last Post: 11-12-2012, 06:01 PM
  2. BigInteger
    By 7cardcha in forum New To Java
    Replies: 9
    Last Post: 10-25-2011, 06:06 AM
  3. BigInteger value of
    By ccie007 in forum New To Java
    Replies: 2
    Last Post: 09-26-2010, 03:46 PM
  4. BigInteger
    By windows.login in forum New To Java
    Replies: 8
    Last Post: 07-13-2010, 01:10 PM
  5. very new... Biginteger problems
    By willemien in forum New To Java
    Replies: 6
    Last Post: 05-02-2010, 03:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •