#I keep getting errors when I update eclipse still

7 messages · Page 1 of 1 (latest)

cyan ferry
#

I got an Error: Main method is not static in class SumAndAverage, please define the main method as:
public static void main(String[] args)
so I'm trying to update my eclipse

tulip hollyBOT
#

This post has been reserved for your question.

Hey @cyan ferry! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

dusk halo
#

The error is saying that your main method doesn't have the static property. Could you post your code here to help confirm whether its an IDE problem or a code problem?

mint shell
#

@cyan ferry copy and paste your code into here, specifically the main method

cyan ferry
#

public class SumAndAverage {
public static void main(String[] args) {
if (args.length != 5) {
System.err.println("Please provide exactly 5 numbers as command-line arguments.");
System.exit(1);
}

    double[] numbers = new double[5];
    double sum = 0;

    for (int i = 0; i < 5; i++) {
        try {
            numbers[i] = Double.parseDouble(args[i]);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format for argument " + (i + 1) + ": " + args[i]);
            System.exit(2);
        }
        sum += numbers[i];
    }

    double average = sum / 5;
    System.out.println("The sum is: " + sum);
    System.out.println("The average is: " + average);
}

}

cyan ferry