2014-11-14 54 views
0

爲什麼Python能夠存儲任意長度的長整數作爲Java,C只能提供64位? 如果在Java中有這樣的方法,請顯示它。long-type in Python vs Java&C

+1

['BigInteger'](https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html)具有任意精度。 – August 2014-11-14 21:51:12

+0

你可能想讀這個 - http://programmers.stackexchange.com/questions/128589/how-to-handle-large-numbers – ha9u63ar 2014-11-14 21:52:31

回答

2

Java中有BigInteger類。

看到這個python幫助文件。

Plain integers (also just called integers) are implemented using long in C, 
which gives them at least 32 bits of precision 
(sys.maxint is always set to the maximum plain integer value for the current platform, 
the minimum value is -sys.maxint - 1). 
Long integers have unlimited precision. 

基本上是一樣的。在Java中,你可以使用。

  • 字節 - 8位
  • 短 - 16位
  • INT - 32位
  • 長 - 64位
  • 的BigInteger

在蟒它自動改變由於其類型爲弱分類,請參閱下面的python代碼

>>> a = 1000 
>>> type(a) 
<type 'int'> 
>>> a = 1000000000000000000000000000000000000000000000000000000000000000 
>>> type(a) 
<type 'long'> 

在java中,你必須自己改變變量的類型。

0

Python存儲無限制的長整數,只要有可用的地址空間,就可以存儲大量數據。

至於Java中,使用的BigInteger類