我對編程完全陌生。我正在閱讀互聯網上的一些教程,還嘗試學習Java編程時Barry Burds「傻瓜式的Java」。我嘗試過所有我能想到但沒有成功的變體。 在一個練習中,我應該讓以下程序在「messageDialogBox」中打印一條消息,該消息應包含程序用戶寫入的數字。不幸的是,當試圖編譯時,我得到以下錯誤消息:有人可以幫我讓代碼工作嗎?代碼有什麼問題?錯誤消息:')'expected,and「not a statement''''expected
5 errors
Addition2.java:24: ')' expected
JOptionPane.showMessageDialog(null, firstnumber "+" secondnumber
^
Addition2.java:25: not a statement
+ sum, "Results", JOptionPane.PLAIN_MESSAGE);
^
Addition2.java:25: ';' expected
+ sum, "Results", JOptionPane.PLAIN_MESSAGE);
^
Addition2.java:25: not a statement
+ sum, "Results", JOptionPane.PLAIN_MESSAGE);
^
Addition2.java:25: ';' expected
+ sum, "Results", JOptionPane.PLAIN_MESSAGE);
的代碼如下:
import javax.swing.JOptionPane;
public class Addition2
{
public static void main(String args[])
{
String firstnumberstring;
String secondnumberstring;
int firstnumber;
int secondnumber;
int sum;
firstnumberstring = JOptionPane.showInputDialog(
"Write first number");
secondnumberstring =
JOptionPane.showInputDialog("Write second number");
firstnumber = Integer.parseInt(firstnumberstring);
secondnumber = Integer.parseInt(secondnumberstring);
sum = firstnumber + secondnumber;
JOptionPane.showMessageDialog(null, firstnumber "+" secondnumber
+ sum, "Results", JOptionPane.PLAIN_MESSAGE);
}
}
謝謝你好多!我是3 +短的標誌。讓它+「+」做到了!再一次謝謝你! – user820913
務必提供所有有用答案並接受回答您的問題的答案/解決您的問題。 – aioobe