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

后端 未结 9 1336
孤独总比滥情好
孤独总比滥情好 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:09

    try: Integer.parseInt(a)+Integer.parseInt(b)

     String a= txtnum1.getText();
     String b= txtnum2.getText(); 
     JOptionPane.showMessageDialog(null,Integer.parseInt(a)+Integer.parseInt(b));
    

提交回复
热议问题