Java 如何从这个程序一开始就回溯我制作的netbeans 8.1

Java 如何从这个程序一开始就回溯我制作的netbeans 8.1,java,netbeans,Java,Netbeans,我有一个我一直为之工作的项目。我正在尝试添加一个选项,以便在用户希望重试时再次运行该项目 如何循环回代码的起点 哪里应该是输入循环代码的正确位置 public static void main(String[] args) { //Input String data types. String input, input1, input2, input3, input4, input5, input6, input7, input8, input9, input10;

我有一个我一直为之工作的项目。我正在尝试添加一个选项,以便在用户希望重试时再次运行该项目

如何循环回代码的起点

哪里应该是输入循环代码的正确位置

public static void main(String[] args) {

    //Input String data types.
    String input, input1, input2, input3, input4, input5, input6, input7, input8, input9, input10;

    //Arithmetic Operators and variables
    int add = 0, sub = 0, mult = 0;
    double div = 0, modulo = 0;

    //Startline of the program
    JOptionPane.showMessageDialog(parentComponent, "Welcome and lets play numbers", "MATHGAME!", 3);//Use "parentComponent" for define dialogs and icons may show up.

    //Ask users to select Operators
    input = JOptionPane.showInputDialog(parentComponent, "Choose an Operator to calculate" + "\n1. Addition" + "\n2. Subtraction" + "\n3. Multiplication"
            + "\n4. Division" + "\n5. Modulo", "OPERATORS", 3);

    //parse selections to input
    int select = Integer.parseInt(input);

    //Use switch for the certain selected operation:
    switch (select) {

        //cast cases for the selected operations
        case 1: //Informations will appear on each cases

            JOptionPane.showMessageDialog(parentComponent, "You've selected Addition", "ADDITION", 2);
            //prompt users how many calculations they want using loops
            input1 = JOptionPane.showInputDialog(parentComponent, "How many Calculation do you want?", "ADDITION", 3);
            int select1 = Integer.parseInt(input1);

            //Declare another Variables to hold the calculations.
            int cal = 1,
             total = 0;
            //use loops for calculations
            while (cal <= select1) {
                //prompt users to enter the numbers to calculate
                input2 = JOptionPane.showInputDialog(parentComponent, "Enter Number to Calculate", "ADDITION", 3);
                add = Integer.parseInt(input2);
                //Increment calculations
                cal++;
                // function of the operator
                total = (int) (add + total);
            }
            // the final answer for the calculation
            JOptionPane.showMessageDialog(parentComponent, "Your Sum is: " + total, "ADDITION", 2);
            break; //break to stop the calculation and let the user to select another operations

        case 2:
            JOptionPane.showMessageDialog(parentComponent, "You've selected Subtraction", "SUBTRACTION", 2);
            input3 = JOptionPane.showInputDialog(parentComponent, "How many Calculation do you want?", "SUBTRACTION", 3);
            int select2 = Integer.parseInt(input3);
            int cal1 = 1,
             total1 = 0;
            while (cal1 <= select2) {
                input4 = JOptionPane.showInputDialog(parentComponent, "Enter Number to Calculate", "SUBTRACTION", 3);
                sub = Integer.parseInt(input4);
                cal1++;
                total1 = (int)  (sub - total1);
            }
            int nom = total1 - sub;
            JOptionPane.showMessageDialog(parentComponent, "Your Difference is: " + (nom), "SUBTRACTION", 2);
            break;

        case 3:
            JOptionPane.showMessageDialog(parentComponent, "You've selected Multiplication", "MULTIPLICATION", 2);
            input5 = JOptionPane.showInputDialog(parentComponent, "How many Calculation do you want?", "MULTIPLICATION", 3);
            int select3 = Integer.parseInt(input5);
            int cal2 = 1,
             total2 = 0;
            while (cal2 <= select3) {
                input6 = JOptionPane.showInputDialog(parentComponent, "Enter Number to Calculate", "MULTIPLICATION", 3);
                mult = Integer.parseInt(input6);
                cal2++;
                total2 = (int) (mult * mult);
            }
            JOptionPane.showMessageDialog(parentComponent, "Your Product is: " + (total2), "MULTIPLICATION", 2);
            break;

        case 4:
            JOptionPane.showMessageDialog(parentComponent, "You've selected Division", "DIVISION", 2);
            input7 = JOptionPane.showInputDialog(parentComponent, "How many Calculation do you want?", "DIVISION", 3);
            int select4 = Integer.parseInt(input7);
            int cal3 = 1,
             total3 = 0;
            while (cal3 <= select4) {
                input8 = JOptionPane.showInputDialog(parentComponent, "Enter Number to Calculate", "DIVISION", 3);
                div = Double.parseDouble(input8);
                cal3++;
                total3 = (int) (double) (div / div);
            }
            JOptionPane.showMessageDialog(parentComponent, "Your Quotient is: " + (total3), "DIVISION", 2);
            break;

        case 5:
            JOptionPane.showMessageDialog(parentComponent, "You've selected Percentage", "PERCENTAGE", 2);
            input9 = JOptionPane.showInputDialog(parentComponent, "How many Calculation do you want?", "PERCENTAGE", 3);
            int select5 = Integer.parseInt(input9);
            int cal4 = 1,
             total4 = 0;
            while (cal4 <= select5) {
                input10 = JOptionPane.showInputDialog(parentComponent, "Enter Number to Calculate", "PERCENTAGE", 3);
                modulo = Double.parseDouble(input10);
                cal4++;
                total4 = (int) (modulo + total4);
            }
            double num = total4 / select5;
            JOptionPane.showMessageDialog(parentComponent, "Your Average is: " + (num), "PERCENTAGE", 2);
            break;
        default: // Default code to prompt error to users that inputs wrong input.
            JOptionPane.showMessageDialog(parentComponent, "Input Out of RANGE!", "ERROR", 2);
            break;

    }
    //Prompt users to do more calculations using loops
            String again = JOptionPane.showInputDialog(parentComponent, "Do you want to calculate more?" + "\n1. Yes"
                    + "\n2. No", "AGAIN?", 3);
            int term = Integer.parseInt(again); //parse for selections
            if (term == 1){

            }
            else {
                JOptionPane.showMessageDialog(parentComponent,"ThankYou");
            }

}
public static Component parentComponent;}
publicstaticvoidmain(字符串[]args){
//输入字符串数据类型。
字符串输入,输入1,输入2,输入3,输入4,输入5,输入6,输入7,输入8,输入9,输入10;
//算术运算符和变量
int add=0,sub=0,mult=0;
双div=0,模=0;
//节目主持人
showMessageDialog(parentComponent,“欢迎并让我们玩数字”,“MATHGAME!”,3);//使用“parentComponent”定义对话框,可能会显示图标。
//要求用户选择操作员
input=JOptionPane.showInputDialog(parentComponent,“选择要计算“+”\n1.加法“+”\n2.减法“+”\n3.乘法的运算符”
+“\n4.除法”+“\n5.模”,“运算符”,3);
//解析要输入的选择
int select=Integer.parseInt(输入);
//将开关用于特定的选定操作:
开关(选择){
//所选操作的强制转换案例
案例1://信息将出现在每个案例上
showMessageDialog(parentComponent,“您已选择添加”,“添加”,2);
//提示用户希望使用循环进行多少计算
input1=JOptionPane.showInputDialog(parentComponent,“您需要多少计算?”,“ADDITION”,3);
int select1=Integer.parseInt(input1);
//声明另一个变量以保存计算。
int cal=1,
总数=0;
//使用循环进行计算

while(cal您可以这样做,即声明一个布尔类型的变量,并在该变量为true时循环您的游戏。 像这样:

JOptionPane.showMessageDialog(parentComponent, "Welcome and lets play numbers", "MATHGAME!", 3);
boolean keepPlaying = true;
while (keepPlaying){
    //your game
    if(term !=1 ){
        JOptionPane.showMessageDialog(parentComponent, "ThankYou");
        keepPlaying = false;
    }
}