在此代码片段中,我无法总结 a
和 b
:
String a = "10";
String b = "20";
JOptionPane.showMessageDialog(null,a+b);
Since a
and b
are defined as String
, this code will concatenate the strings and output 10+20=1020
.
我怎样才能得到它而不是求和 a
和 b
并输出 10+20=30
?
原文由 celikgumusdag 发布,翻译遵循 CC BY-SA 4.0 许可协议
Java 为原始类型提供了解析方法。因此,根据您的输入,您可以使用 Integer.parseInt、Double.parseDouble 或其他。