Java – am I right? I’ve been collecting compiler errors

I'm not sure if I write correctly I checked my notes to make sure I used all the appropriate symbols, but I've been receiving errors, such as: ';' Expectations, not statements What did I miss???

import java. util. Scanner;

Public class 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;
    }
}

}

Solution

Your method (for example, showemployees) should not be in the main method and should not have a semicolon after the Declaration:

change

int showEmployees();
{
   ...
}

to

int showEmployees()
{
   ...
}

And move it out of the main method

The same applies to getdays and averagedays

Your method also seems to be missing some return statements Each execution path must have a return statement For example, getdays has only one return statement in the while loop There must be at least one return statement after the while loop in case the while loop is never entered

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>