import javax.swing.*;
public class A extends JFrame{
public static void main(String args[]){
int input2;
boolean Int = false; while(!Int){
String input = JOptionPane.showInputDialog("Enter a integer");
input2 = Integer.parseInt(input);
if(input2 < 3){
    Int = false;
                  }
                                  else{
                                       Int = true;
                                       System.out.println("good"); }
                  
}
System.exit(0);  }
 }

解决方案 »

  1.   

    我怎么觉得是应该先输入一个数值,再进行比较呢,象这样:
    public class A{
    public static void main(String args[]){
    int input2, input4; String input = JOptionPane.showInputDialog("Enter a integer");
    input2 = Integer.parseInt(input);                 boolean Int = false;
    if(input2 < 3){
        while(!false){
    String input2 = JOptionPane.showInputDialog("Enter a integer");
                      }   }
                      else{
                      Int = true;
                      System.out.print("good");
      }System.exit(0);
     }
     }
    虽然是不对,但是我总是不知道为什么这样,思路是错误的
      

  2.   

    import javax.swing.*;
    public class A
    {
            public static void main(String args[])
            {
                    int input2;
                    //boolean Int = false;
                    int Int=0;
                    while(Int==0)
                    {
                    String input = JOptionPane.showInputDialog("Enter a integer");
                     try{
                         input2 = Integer.parseInt(input);
                         if(input2 < 3)
                         {
                           Int =0;
                          }
                          else
                          {
                           Int = 1;
                           System.out.println("good"); }
                         }
                      catch(NumberFormatException e)
                      {}//校验输入是否为整数
                       //System.exit(0);放在此处无论输入什么将退出
                     }
                System.exit(0);
             }
    }
      

  3.   

    简单点就行,直接使用while(true),每次询问输入,检查输入,如果输入>3,break.