How to solve a start of type error in java?

Anikin Skywalker :

I am a beginner and was writing a code that would input three integers. It would find the maximum integer and return its position. code:

import java.util.Scanner;

public class Main {
    public static int getNumberOfMaxParam(int a, int b, int c) {
        int max = a;
        int count = 1;
        if (b > max) {
            count = 2;
        }

        if (c > max) {
            count = 3;
        }
        return count;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        System.out.print(getNumberOfMaxParam(a, b, c));
    }
}

However, I keep getting this error:

Compilation error
Main.java:1: error: illegal start of type
import java.util.Scanner;
^
Main.java:1: error: <identifier> expected
import java.util.Scanner;
                        ^
2 errors

What correction should I make? I've tried to read other answers on the same issue but unlike others I'm not using a try-catch block. Any help will be appreciated.

Eugene :

After reproducing the issue, I can say this particular problem does not require you to have a class declaration. It is enough to provide only method's signature and body, even if IDEA gives you a warning.

enter image description here

As you see, the solution was accepted, despite the warning.

This might be confusing, as other problems on this platform do require you to provide class declaration. I think, it depends on the author of the particular problem.

Also, please note, the task does not ask you for an input, so import of java.util.Scanner and the corresponding method are not needed.

I advise you to reset the problem by pressing Solve again button on the site and start over again. If you are having trouble resetting it, remove the problem's module from the project or delete it from the disk first.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=31756&siteId=1