How do I convert a String to a BigInteger?

前端 未结 6 1409
自闭症患者
自闭症患者 2020-11-30 08:09

I\'m trying to read some really big numbers from standard input and add them together.

However, to add to BigInteger, I need to use BigInteger.valueOf(long);

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 08:47

    Instead of using valueOf(long) and parse(), you can directly use the BigInteger constructor that takes a string argument:

    BigInteger numBig = new BigInteger("8599825996872482982482982252524684268426846846846846849848418418414141841841984219848941984218942894298421984286289228927948728929829");
    

    That should give you the desired value.

提交回复
热议问题