如何使java程序重复运行

如何使java程序重复运行,java,swing,Java,Swing,我正在尝试运行一个Java程序来显示9个输入框,请求名称和考试分数,并在消息框中显示每个分数的名称和相应分数。我试过这样做: import javax.swing.JOptionPane; public class StudentGrade { public static void main(String[] args) { String inputname; String inputscore; int number; inputcourse = JOpti

我正在尝试运行一个Java程序来显示9个输入框,请求名称和考试分数,并在消息框中显示每个分数的名称和相应分数。我试过这样做:

import javax.swing.JOptionPane;
public class StudentGrade {
  public static void main(String[] args) {
    String inputname;
    String inputscore;
    int number;
    inputcourse = JOptionPane.showInputDialog("Enter name");
    inputscore = JOptionPane.showInputDialog("Enter score");
    number = Integer.parseInt(inputscore);
    if (number < 40){ 
      System.out.println ((inputcourse) + " " + "D"); }
    else if (number <50){
      System.out.println((inputcourse) + " " + "C");}
    else if (number <60){
      System.out.println((inputcourse) + " " + "B");}
    else System.out.println((inputcourse) + " " + "A");}
 }

但是,这只能运行一次。拜托,我怎样才能让它跑九次呢?谢谢。

要在控制结构中循环,可以使用for、while循环或do-while循环。对于For循环,您应该尝试:

public class StudentGrade{
     public static void main(String[] args){
         for (int i=0; i<9; i++){ repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
         int i=0;
         while (i++ < 9){ //repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
          int i=1;
          do{ //repeat 9 times
             // all the code you have in your main method now
          }while (i++ < 9);
     }
}
在一段时间内,您应该尝试:

public class StudentGrade{
     public static void main(String[] args){
         for (int i=0; i<9; i++){ repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
         int i=0;
         while (i++ < 9){ //repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
          int i=1;
          do{ //repeat 9 times
             // all the code you have in your main method now
          }while (i++ < 9);
     }
}
对于do while循环,您应该尝试:

public class StudentGrade{
     public static void main(String[] args){
         for (int i=0; i<9; i++){ repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
         int i=0;
         while (i++ < 9){ //repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
          int i=1;
          do{ //repeat 9 times
             // all the code you have in your main method now
          }while (i++ < 9);
     }
}

希望这有帮助。

要在控制结构中循环,可以使用for、while循环或do-while循环。对于For循环,您应该尝试:

public class StudentGrade{
     public static void main(String[] args){
         for (int i=0; i<9; i++){ repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
         int i=0;
         while (i++ < 9){ //repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
          int i=1;
          do{ //repeat 9 times
             // all the code you have in your main method now
          }while (i++ < 9);
     }
}
在一段时间内,您应该尝试:

public class StudentGrade{
     public static void main(String[] args){
         for (int i=0; i<9; i++){ repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
         int i=0;
         while (i++ < 9){ //repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
          int i=1;
          do{ //repeat 9 times
             // all the code you have in your main method now
          }while (i++ < 9);
     }
}
对于do while循环,您应该尝试:

public class StudentGrade{
     public static void main(String[] args){
         for (int i=0; i<9; i++){ repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
         int i=0;
         while (i++ < 9){ //repeat 9 times
              // all the code you have in your main method now
         }
     }
}
public class StudentGrade{
     public static void main(String[] args){
          int i=1;
          do{ //repeat 9 times
             // all the code you have in your main method now
          }while (i++ < 9);
     }
}

希望这有帮助。

试试这个,它会有用的。在代码中检查Inputname和InputCourse 或者将inputCourse更改为inputName

import javax.swing.JOptionPane;

public class world {
    public static void main(String[] args) {
        String inputname;
        String inputscore;
        int number;
        for(int i=0;i<9;i++){
            inputname = JOptionPane.showInputDialog("Enter name");
            inputscore = JOptionPane.showInputDialog("Enter score");
            number = Integer.parseInt(inputscore);
            if (number < 40){ 
               System.out.println ((inputname) + " " + "D");
            }else if (number <50){
               System.out.println((inputname) + " " + "C");
            }else if (number <60){
               System.out.println((inputname) + " " + "B");
            }else {
               System.out.println((inputname) + " " + "A");
            }
        }
    }
}

试试这个,会有用的。在代码中检查Inputname和InputCourse 或者将inputCourse更改为inputName

import javax.swing.JOptionPane;

public class world {
    public static void main(String[] args) {
        String inputname;
        String inputscore;
        int number;
        for(int i=0;i<9;i++){
            inputname = JOptionPane.showInputDialog("Enter name");
            inputscore = JOptionPane.showInputDialog("Enter score");
            number = Integer.parseInt(inputscore);
            if (number < 40){ 
               System.out.println ((inputname) + " " + "D");
            }else if (number <50){
               System.out.println((inputname) + " " + "C");
            }else if (number <60){
               System.out.println((inputname) + " " + "B");
            }else {
               System.out.println((inputname) + " " + "A");
            }
        }
    }
}

将代码放入for循环中:

 for(int i=0; i<9; i++){
     inputcourse = JOptionPane.showInputDialog("Enter name");
     inputscore = JOptionPane.showInputDialog("Enter score");
     number = Integer.parseInt(inputscore);
     if (number < 40){ 
         System.out.println ((inputcourse) + " " + "D");
     } else if (number <50){
         System.out.println((inputcourse) + " " + "C");
     } else if (number <60){
         System.out.println((inputcourse) + " " + "B");
     } else {
         System.out.println((inputcourse) + " " + "A");
     }
 }

将代码放入for循环中:

 for(int i=0; i<9; i++){
     inputcourse = JOptionPane.showInputDialog("Enter name");
     inputscore = JOptionPane.showInputDialog("Enter score");
     number = Integer.parseInt(inputscore);
     if (number < 40){ 
         System.out.println ((inputcourse) + " " + "D");
     } else if (number <50){
         System.out.println((inputcourse) + " " + "C");
     } else if (number <60){
         System.out.println((inputcourse) + " " + "B");
     } else {
         System.out.println((inputcourse) + " " + "A");
     }
 }
请参见并注意教程WAAAAAAAY的“螺母和螺栓”部分中的说明(&A)。。在教程的“创建GUI”部分之前?将此视为一个强烈的暗示,即您过早地开始制作GUI。它们比看起来要困难得多。请参阅并注意教程WAAAAAAAAY的“螺母和螺栓”部分。。在教程的“创建GUI”部分之前?将此视为一个强烈的暗示,即您过早地开始制作GUI。他们比看起来要困难得多。如果这有助于解决问题,请求求你。如果这有助于解决问题,请求求你。