我正在尝试为我所在的编程类创建一个计算器,它包含用户输入然后进行数学运算。我选择使用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和+之间(fnum + snum)
已定义变量,并且此过程使用System.out.println方法正常工作。
有关正在发生的事情的任何建议?
答案 0 :(得分:0)
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));
答案 1 :(得分:0)
这一行是罪魁祸首,
(2) "The addition of "+fnum+" and "+snum+" is "(fnum+snum)"\n"+
而不是使用此
(2) "The addition of "+fnum+" and "+snum+" is "+(fnum+snum)+"\n"+