How can I find the sum of two numbers which are in String variables?

后端 未结 9 1374
孤独总比滥情好
孤独总比滥情好 2020-12-07 05:36

In this code fragment, I can\'t sum a and b:

String a = \"10\";
String b = \"20\"; 
JOptionPane.showMessageDialog(null,a+b);
         


        
9条回答
  •  天涯浪人
    2020-12-07 06:22

    use BigInteger class to perform largely in length string addition operation.

    BigInteger big = new BigInteger("77777777777777777777888888888888888888888888888856666666666666666666666666666666");
            BigInteger big1 = new BigInteger("99999999999999995455555555555555556");
            BigInteger big3 =   big.add(big1);
    

提交回复
热议问题