系统退出函数使用错误

问题描述 投票:0回答:0

我在 if...else 块中使用了

System.exit()
函数,但是 它显示了我的语法错误和运行时错误, 其中一个主要错误是:

main.java:58: 错误:类 System 中的方法退出不能应用于给定类型; 系统.exit(); ^ 要求:整数 发现:没有参数 原因:实际和形式参数列表的长度不同 1 个错误。

我的密码是:

import java.util.Scanner;
class main
{
    /*      Instance variables:
     *      int vno
     *      int hours
     *      double bill;
     *
     *      Member methods:
     *      void frontend-1()
     *      void backend()
     *      To compute the parking charge at the rate $3 for the first
     *      hour of part thereof, and $1.50 for each additon hour of part therefore
     *      void frontend-2()                                         */
    
    int vno;            //to store the vehicle number
    int hours;          //to store the hours the vehicle had been
    String name;            //to store the name of customer
    double bill;        //to store the total bill
    
    main()
    {
        vno=0;
        hours=0;
        name="";
        bill=0.0;
    }
    void frontend1()
    {
        //Initializing the scanner class
        Scanner sc = new Scanner(System.in);
        //Taking input from the user
        System.out.println("\t|<NIR-NIMESH PARKING LOT>|");
        System.out.println("-------------------------------");
        System.out.print("name of customer: ");
        name = sc.nextLine();
        System.out.println();
        System.out.print("time of vehicle stay(in hours): ");
        hours = sc.nextInt();
        System.out.println("THANK YOU");
    }
    void backend()
    {
        //if the car is parked for less than one hour
        if(hours<1)
        {
            bill=3.0;
        }
        //if the car is parked for more than one hour
        else if(hours>1)
        {
            bill = 1.50*hours;
        }
        //if invalid input is received from the user
        else
        {
            System.out.println("INVALID INPUT");
            System.exit();
        }
    }

    void frontend2()
    {
        System.out.println("_________________________________");
        System.out.println("Name: "+name);
        System.out.println("Stay of the vehicle in hour: "+hours);
        System.out.println("Total Bill: "+bill);    
    }

    public static void main()
    {
        main obj = new main();
        obj.frontend1();
        obj.backend();
        obj.frontend2();
    }

}



试过好几种方法,也试过把system.exit()函数放在不同的地方,但都没有用

java java.util.scanner system.exit
© www.soinside.com 2019 - 2024. All rights reserved.