繁体   English   中英

在Java中,如何获得数字字符串的子序列,其索引长度可以为10 ^ 5位数

[英]In Java how can I get a subsequence of number string whose indices can be as 10^5 digits long

在Java中,如何获取BigInteger的子序列,其索引长度可以为10 ^ 5位。

示例:BigInteger的长度是10 ^ 5。 我必须找到索引10 ^ 3和10 ^ 4之间的子序列

您可以使用:

String yourSubstring = Str.substring(9999, 10000);

这将为您提供从10 ^ 3到10 ^ 4的字符串。

要将BigInt转换为String,可以使用:

String str = yourBigInt.toString();

学习这段代码,看看它是否可以解决您的问题。 如果没有,也许您会在其中找到一些有用的信息。

public class TestBigInteger 
{
    public static void main( String[] args )
    {
        String makeNumber = "";
        int numberOfDigits = 10000;
        String newNumberString = "";
        Random random = new Random();
        BigInteger result;


        for ( int i = 0; i < numberOfDigits; i++ ) {
            makeNumber += random.nextInt( 9 );
        }
        newNumberString = makeNumber.substring( 100, 999);
        result = new BigInteger( newNumberString );

    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM