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

时间:2016-07-29 22:46:09

标签: java biginteger subsequence

在Java中如何获得BigInteger的子序列,其索引可以是10 ^ 5位数。

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

2 个答案:

答案 0 :(得分:1)

您可以使用:

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

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

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

String str = yourBigInt.toString();

答案 1 :(得分:0)

研究此代码,看看它是否解决了您的问题。如果它没有,也许你会发现其中的一些信息会有所帮助。

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

    }

}