在变量中存储大量数字的正确方法

编程入门 行业动态 更新时间:2024-10-13 06:14:49
本文介绍了在变量中存储大量数字的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想研究数字,但无论是基本数字,我一直在写斐波那契数列的算法和用于查找素数的蛮力路径!

I would like to play around with numbers and however elementary, Ive been writing algorithms for the fibonacci sequence and a brute force path for finding prime numbers!

我不是程序员,只是一个数学家.

Im not a programmer, just a math guy.

但是,我经常遇到一个安静的问题,就是长而长的双排和浮子经常没有空间.

However, a problem I run into quiet often is that a long long, double and floats often run out of room.

如果我想继续在JAVA中工作,可以用什么方式创建自己的数据类型,以免空间不足.

If I wanted to continue to work in JAVA, in what way can I create my own data type so that I dont run out of room.

从概念上讲,我想像这样将3个双打组合在一起,

Conceptually, I thought to put 3 doubles together like so,

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); } } }

有没有更好的方法可以做到这一点,

is there a better way to do this,

我希望有一天能说

mydataType X = 18476997032117414743068356202001644030185493386634 10171471785774910651696711161249859337684305435744 58561606154457179405222971773252466096064694607124 96237204420222697567566873784275623895087646784409 33285157496578843415088475528298186726451339863364 93190808467199043187438128336350279547028265329780 29349161558118810498449083195195450098483937752272570 52578591944993870073695755688436933812779613089230 39256969525326162082367649031603655137144791393234 7169566988069

mydataType X = 18476997032117414743068356202001644030185493386634 10171471785774910651696711161249859337684305435744 58561606154457179405222971773252466096064694607124 96237204420222697567566873784275623895087646784409 33285157496578843415088475528298186726451339863364 93190808467199043187438128336350279547028265329780 29349161558118810498449083195450098483937752272570 52578591944993870073695755688436933812779613089230 39256969525326162082367649031603655137144791393234 7169566988069

或在此网站

我也尝试过

package main; import java.math.BigInteger; public class run { BigDecimal a = 184769970321174147430683562020019566988069; public static void main(String[] args) { } }

但是它似乎仍然超出范围

But it still seems to be out of range

推荐答案

为此目的使用BigDecimal(而不是double)和BigInteger(而不是int,long),但是您只能通过他们的方法与他们合作.没有运算符,可以使用.

Use BigDecimal (instead of double), and BigInteger (instead of int, long) for that purpose, But you can only work with them by their methods. No operators, can be used.

像这样使用:

BigInteger big = new BigInteger("4019832895734985478385764387592") // Strings... big.add(new BigInteger("452872468924972568924762458767527");

与BigDecimal

更多推荐

在变量中存储大量数字的正确方法

本文发布于:2023-10-18 15:07:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   正确   数字   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!