문자열이 정수로 구문 분석되었으므로 if 문의 조건이 올바르게 설정됩니다. if 문이 실행되지 않는 이유는 무엇입니까? 응답이있는 MessageDialog가 나타나지 않는 이유는 무엇입니까?문이 실행되지 않는 경우
class process{
public static void whoIs(){
JFrame frame=new JFrame("The Oldest");
String a=JOptionPane.showInputDialog(frame, "Enter, please, the first name and age:", "QUIZ: Who is the Oldest", JOptionPane.QUESTION_MESSAGE);
String b=JOptionPane.showInputDialog(frame, "Enter, please, the second name and age:", "QUIZ: Who is the Oldest", JOptionPane.QUESTION_MESSAGE);
String age1=a.replaceAll("[^\\d]","");
String age2=a.replaceAll("[^\\d]","");
String name1=a.replaceAll("\\d","");
String name2=b.replaceAll("\\d","");
int age1int=Integer.parseInt(age1);
int age2int=Integer.parseInt(age2);
if (age1int>age2int){
JOptionPane.showMessageDialog(frame, name1+ " is the oldest!", "QUIZ: Who is the Oldest?", JOptionPane.INFORMATION_MESSAGE);
}
if (age2int>age1int) {
JOptionPane.showMessageDialog(frame, name2+ " is the oldest!", "QUIZ: Who is the Oldest?", JOptionPane.INFORMATION_MESSAGE);
}
}
}
는 사소한는 - 그냥 디버깅, 코드 – nogard
짧고 깨끗하거나 그냥 if 문 전에 age1int 및 age2int의 값을 출력하고 그 값을 볼 두 조건을 인쇄하고 –
을 확인합니다. 그렇다면 당신은 –