繁体   English   中英

JAVA,如何从头开始重新启动我的程序?

[英]JAVA, How to restart my program from the start?

我是Java的新手,我正在做一些练习,创建了一个if语句和else if语句,以便当用户单击2时它将从头开始程序。

问题是在else if(yesNo == 2)处,我不知道应该从那里开始编写哪种代码来启动程序。 有谁能够帮助我? 谢谢。

    if (option == 1) {
        System.out.println("1: DAF");
        System.out.println("2: Mercedes-benz");
        model = in.nextInt();

        if (model == 1) {
            System.out.println("Model: " + mixer2.getModel());
            System.out.println("Age: " + mixer2.getAge());
            System.out.println("Cost: " + mixer2.getCost());
            System.out.println("Capacity: " + mixer2.getCapacity() + "  squares meters");

            System.out.println("For how long do you want the vehicle to hire?, maximum is 12 months and every month cost 4000");
            hireVehicle = in.nextInt();
            cost = 4000 * hireVehicle;
            System.out.println("The total cost is " + cost + " Do you want to proceed?");
            System.out.println("1: yes");
            System.out.println("2: no");
            yesNo = in.nextInt();


            if (yesNo == 1) {
                System.out.println("Now, please enter your first name to complete the contract");
                String name = in.next();
                System.out.println("CUSTOMER CONTRACT");
                System.out.println("Customer name: " + name);
                System.out.println("Duration: " + hireVehicle + " months");
                System.out.println("Date: " + date.date1());
            }
            else if (yesNo == 2){

            }

您可以使用像这样的循环:

boolean repeat = True;
while (repeat)
{
    if (yesNo ==1)
        repeat = False;
    else if (yesNo == 2)
        repeat = True;
}

使用do while循环可能会更容易,但我听说它们很脏

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM