gpt4 book ai didi

java - Eclipse 上的 JOptionPane 错误

转载 作者:行者123 更新时间:2023-12-02 06:43:18 27 4
gpt4 key购买 nike

我对 Java 非常陌生(即 AP 计算机科学 A 的第 2 周)。我们必须使用 JOptionPane 来制作消息框以用于数学运算。我的代码在学校很好,但我必须重新格式化它,因为我将它保存在 Facebook 上(没有其他选择)。现在,我在所有 JOptionPane 行上都收到错误,提示“此行有多个标记”和“标记上的语法错误”。我该如何解决这个问题。这是代码(请仅修复我所要求的内容,没有其他内容,我知道代码可能很奇怪)

import javax.swing.JOptionPane;

public class OptioPane {

public static void main(String[] args) {
}

String a = JOptionPane.showInputDialog("Enter an integer");
String b = JOptionPane.showInputDialog("Input another");
int x = Integer.parseInt(a);
int y = Integer.parseInt(b);
JOptionPane.showMessageDiaglog(null, "The numbers added together is " +(x+y));

String c = JOptionPane.showInputDialog("Enter an integer");
String d = JOptionPane.showInputDialog("Input another");
int f = Integer.parseInt(c);
int g = Integer.parseInt(d);
JOptionPane.showMessageDialog(null, "The second number subtracted from the first number is " +(f-g));

String s = JOptionPane.showInputDialog("Enter an integer");
String r = JOptionPane.showInputDialog("Input another");
int w = Integer.parseInt(a);
int q = Integer.parseInt(b);
JOptionPane.showMessageDialog(null, "The numbers multiplied together is " +(w*q));

String k = JOptionPane.showInputDialog("Enter an integer");
String j = JOptionPane.showInputDialog("Input another");
int n = Integer.parseInt(a);
int m = Integer.parseInt(b);
JOptionPane.showMessageDialog(null, "The first number divided by the second number is " +(n/m));

String fir = JOptionPane.showInputDialog("Enter an integer");
String tir = JOptionPane.showInputDialog("Input another");
int ah = Integer.parseInt(a);
int bh = Integer.parseInt(b);
JOptionPane.showMessageDialog(null, "The first number modulated by the second number is " +(ah*bh));
}

最佳答案

基本上,代码主体位于任何可执行上下文之外(不是它所属的位置)....

public class OptioPane {

public static void main(String[] args) {
}

/* All your stuff - out of bounds and behaving badly */

}

相反,您需要将此代码放置在可执行上下文中,例如 main 方法...

public class OptioPane {

public static void main(String[] args) {
/* All your stuff - playing nicely */
}


}

哦,添加这一行...

JOptionPane.showMessageDiaglog(null, "The numbers added together is " +(x+y));

错了,看Dialog中多了一个g,应该是...

JOptionPane.showMessageDialog(null, "The numbers added together is " +(x+y));

关于java - Eclipse 上的 JOptionPane 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18907228/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com