当前位置: 首页 > 知识库问答 >
问题:

我写对了吗?我不断收到编译器错误

芮化
2023-03-14

public类EmployeeAbsences{public static void main(String[]args

Scanner keyboard = new Scanner (System.in);

employees = showEmployees();
totaldays = getDays(employees);
average = averageDays(employees, totaldays);

System.out.print("Your employees averaged " + average + " days absent.");


int showEmployees();

{
    int employees;

    System.out.print("How many employees do you have?");
    employees = keyboard.next.Int();

    while (employees > 0)
    {
        if (employees < 0) {
            System.out.print("Please enter a positive number.");
        }
        else
            {
                return employees;
            }
    }


}

int getDays(int employees);

{
    int totaldays = 0;
    int days;

    for (int x = 0; x <= days; x++)
    {
        System.out.print("How many days was Employee #" + x + " absent?");
        days = keyboard.next.Int();
        totaldays = days;
        totaldays = totaldays += days;
    }

    while (days > 0)
    {
        if (days < 0) { 
            System.out.print("Please enter a positive number."); 
        }
        else 
            {
                return totaldays;
            }
    }

}

double averageDays(employees, totaldays) 

{
    int totaldays;
    int employees;
    double average;

    average = totaldays/employees;
    {
        return average;
    }
}

}

共有1个答案

阎单鹗
2023-03-14

您的方法(例如showEmployees)不应该在main方法中,并且它们的声明后面不应该有分号:

改变

int showEmployees();
{
   ...
}

int showEmployees()
{
   ...
}
 类似资料: