简体   繁体   中英

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

In Java how can I get a subsequence of BigInteger whose indices can be 10^5 digits long.

Example : BigInteger length is 10^5 . I have to find subsequence between index 10^3 and 10^4

You can use:

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

This is will give you the string from 10^3 to 10^4.

To convert a BigInt to String you can use:

String str = yourBigInt.toString();

Study this code and see if it solves your question. If it doesn't, maybe you will find some information within that will help.

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

    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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