Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 单击“否”时系统未退出_Java - Fatal编程技术网

Java 单击“否”时系统未退出

Java 单击“否”时系统未退出,java,Java,您好,我正在使用java,由于某种原因,当我在对话框上单击“否”时,它没有退出,而是继续询问学生姓名“publicstaticvoidmain(String[]args){ }`您的代码只是复制了JOptionPane的值。YES\u NO\u OPTION(0)到welcome中,然后您将它与JOptionPane进行比较。YES\u OPTION也是0,因此0==0将始终为真,因此if块将始终执行 showConfirmDialog将为您提供一个int结果,您必须将其存储在某个变量中,因此请

您好,我正在使用java,由于某种原因,当我在对话框上单击“否”时,它没有退出,而是继续询问学生姓名“publicstaticvoidmain(String[]args){


}`

您的代码只是复制了
JOptionPane的值。YES\u NO\u OPTION
(0)到
welcome
中,然后您将它与
JOptionPane进行比较。YES\u OPTION
也是0,因此
0==0
将始终为真,因此
if
块将始终执行

showConfirmDialog
将为您提供一个
int
结果,您必须将其存储在某个变量中,因此请像这样使用它

int welcome;

      // store the output result of showConfirmDialog in welcome

      welcome=JOptionPane.showConfirmDialog(null, "Woild you like to input grades on the students?",
                "Grade",JOptionPane.YES_NO_OPTION);

      // compare result with predefined positive value i.e JOptionPane.YES_OPTION
     if (welcome == JOptionPane.YES_OPTION){

您确定它到达了else语句吗
int welcome;

      // store the output result of showConfirmDialog in welcome

      welcome=JOptionPane.showConfirmDialog(null, "Woild you like to input grades on the students?",
                "Grade",JOptionPane.YES_NO_OPTION);

      // compare result with predefined positive value i.e JOptionPane.YES_OPTION
     if (welcome == JOptionPane.YES_OPTION){