我应该如何存储极大的数据类型 [英] How should I store a extremely large Data Type

查看:120
本文介绍了我应该如何存储极大的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前提出有关超大数字输入的问题。数字可以在0-10 ^ 50之间。我已就此做过研究,但我没有遇到任何可以帮助我的事情。最接近的是BigInteger,但这对我的程序没有帮助,因为它可以防止编辑Big Integer变量,尽管它可以存储无限大的数字。我也尝试了双打,但是在对数字进行操作时,他们对我的程序做了奇怪的事情。任何建议或解决方法?

I am currently posed with an issue regarding a super large number input. The number may range from 0 - 10^50. I have done research regarding this, but I did not run into anything that could help me. The closest thing was a BigInteger, but that does not help with my program as it prevents editing the Big Integer variable although it can store infinitely large numbers. I also tried doubles, but they did weird things to my program when doing operations on the numbers. Any suggestions or work-around?

推荐答案

您可以在java中创建和编辑BigInteger,例如:

You can create and edit BigInteger In java, e.g.:

BigInteger bigInteger = new BigInteger("3");
bigInteger = bigInteger.pow(600);
bigInteger = bigInteger.add(new BigInteger("20"));
bigInteger = bigInteger.subtract(new BigInteger("20"));
bigInteger = bigInteger.multiply(new BigInteger("20"));
bigInteger = bigInteger.divide(new BigInteger("20"));

你可以将BigInteger的任何部分作为整数,例如:

And you can get any part of BigInteger as an Integer, e.g.:

int i = Integer.parseInt(bigInteger.toString().substring(3, 8));

我希望这会对你有帮助。

I hope this will help you.

这篇关于我应该如何存储极大的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆