• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Biginteger

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i wrote a program which exceeded the ranges of int so would print a constant value. At the Sun forums, they said to use BigInteger.



the code allows any number to be shown. i looked up the docs on the Math class but could not understand how to use any of its objects. for example

what does this mean ? BigInteger.valueOf(2)

and also, in the docs
multiply(BigInteger val) is present which says Returns a BigInteger whose value is (this * val) how do i use it in my programs? i mean what is the format?


Ali
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BigInteger.valueOf(2) returns an BigInteger with the value 2. So, you declare two to be a BigInteger with the value 2.
Multiply() also returns the result of the operation, so you do

After this, myBigInt is a BigInteger with value 4, since you added it to itself, and 2 + 2 = 4.
Same goes for the other, such as BigInteger.multiply().
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic