我正在尝试为我所参加的编程类制作一个计算器,该计算器会结合用户输入然后进行数学运算。我选择将JOptionPane
用于此分配的用户输入部分,并且一切进展顺利,直到我要求Java在JOptionPane
消息对话框中将字符串与某些先前定义的变量连接起来为止。
我正在使用DrJava。
我收到错误:
Error: unexpected type
required: class
found: value
这是我的代码:
(Line 1) JOptionPane.showMessageDialog(null, "Thank you! Here are your results:\n"+
(2) "The addition of "+fnum+" and "+snum+" is "(fnum+snum)"\n"+
(3) "The subtraction of "+fnum+" and "+snum+" is "+(5-3));
我在游标介于fnum和+ in(fnum + snum)之间的第二行收到错误
已经定义了变量,并且使用System.out.println方法可以正常执行此过程。
有什么建议吗?
最佳答案
OptionPane.showMessageDialog(null, "Thank you! Here are your results:\n"+
"The addition of "+fnum+" and "+snum+" is "+(fnum+snum)+"\n"+
"The subtraction of "+fnum+" and "+snum+" is "+(5-3));
关于java - 字符串和变量串联的JOptionPane错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28255586/