我想玩弄数字,无论多么简单,我一直在编写斐波那契数列的算法和寻找素数的强力路径!
我不是程序员,只是一个数学家。
然而,我经常遇到的一个问题是,long long、double 和 float 经常会出现空间不足的情况。
如果我想继续在JAVA中工作,我可以通过什么方式创建自己的数据类型,这样我就不会用完空间。
从概念上讲,我想像这样将 3 个双打放在一起,
public class run {
static double a = 0;
static double b = 0;
//static double c = 0;
static void bignumber(boolean x) {
if (x == true && a < 999999999) {
++a;
} else if (x == true && a == 999999999) {
++b;
a = 0;
}
System.out.print(b + "." + a + " \n");
}
public static void main(String[] args) {
while(true) {
bignumber(true);
}
}
}
有一个更好的方法吗,
我希望有一天能够说
mydataType X = 18476997032117414743068356202001644030185493386634
10171471785774910651696711161249859337684305435744
58561606154457179405222971773252466096064694607124
96237204420222697567566873784275623895087646784409
33285157496578843415088475528298186726451339863364
93190808467199043187438128336350279547028265329780
29349161558118810498449083195450098483937752272570
52578591944993870073695755688436933812779613089230
39256969525326162082367649031603655137144791393234
7169566988069
或在以下位置找到的任何其他号码这个网站 http://www.rsa.com/rsalabs/node.asp?id=2093
我也尝试过
package main;
import java.math.BigInteger;
public class run {
BigDecimal a = 184769970321174147430683562020019566988069;
public static void main(String[] args) {
}
}
但好像还是超出了范围
Use BigDecimal
(代替double
), and BigInteger
(代替int
, long
)为此目的,但你只能按照他们的方法与他们合作。无需运算符,即可使用。
像这样使用:
BigInteger big = new BigInteger("4019832895734985478385764387592") // Strings...
big.add(new BigInteger("452872468924972568924762458767527");
与相同BigDecimal
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)