如果 else 分支从未使用过

If else branch never used

我正在使用 if else 并写下一些代码突然发生 else 说分支从未被使用过...但它应该可以工作。

语句看起来像这样

JOptionPane.showConfirmDialog(null,full_name+"\n"+number_age+"\n"+gender+"\n"+address+
                 "\n"+birthday+"\n"+cell_no,"CHECK INFORMATION!",JOptionPane.YES_NO_OPTION);
if(true){
    JOptionPane.showMessageDialog(null,"Thank you for Entering");
}else{
    JOptionPane.showMessageDialog(null,"Please Retry");
}

检查 JOptionPane.showConfirmDialog 响应并与 JOptionPane.YES_NO_OPTION 进行比较:

int answer = JOptionPane.showConfirmDialog(null,full_name+"\n"+number_age+"\n"+gender+"\n"+address+
                 "\n"+birthday+"\n"+cell_no,"CHECK INFORMATION!",JOptionPane.YES_NO_OPTION);
if (JOptionPane.YES_OPTION == answer)) {
    JOptionPane.showMessageDialog(null,"Thank you for Entering");
} else {
    JOptionPane.showMessageDialog(null,"Please Retry");
}