如果语句没有运行

Ins*_*ion 0 java if-statement joptionpane

字符串被解析为整数,因此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);
            }

     }
}
Run Code Online (Sandbox Code Playgroud)

Ruc*_*era 5

你的两个年龄相同,你的if条件不匹配,因为你没有考虑平等.我想你错过了这个,下次尝试使用调试器,然后你可以自己识别这些问题.

 String age1=a.replaceAll("[^\\d]","");
 String age2=a.replaceAll("[^\\d]","");
Run Code Online (Sandbox Code Playgroud)

这应该改为以下.

  String age1=a.replaceAll("[^\\d]","");
  String age2=b.replaceAll("[^\\d]","");
Run Code Online (Sandbox Code Playgroud)