Java Newbie error: cannot find symbol

Java Newbie error: cannot find symbol

我想让此人在控制台中输入 112,然后按回车键,然后以 "Hello, Mars." 作为答案结束。

我卡在 "error: cannot find symbol" 上了。

import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        int n1 = userVar;

        switch ( userVar )
        {
            case 111:
                System.out.println("Hello, Earth.");
                break;
            case 112:
                System.out.println("Hello, Mars.");
                break;
            case 113:
                System.out.println("Hello, Jupiter.");
                break;
            default:
                System.out.println("Hello, Space.");
        }

        Scanner keyboard = new Scanner(System.in);
        n1 = keyboard.nextInt();
    }
}

现在,我尝试将 int 更改为

int userVar;

        Scanner keyboard = new Scanner(System.in);
        userVar = keyboard.nextInt();

但最终陷入了 "error: variable userVar might not have been initialized"。请注意,我正在 Ideone 上执行此操作。

首先,给userVar一个默认值:

int userVar = 0;

然后尝试为其分配用户输入:

Scanner keyboard = new Scanner(System.in);
userVar = keyboard.nextInt();
public class main(){
    public static void main(String []args){
       int userVar = 0;
       System.out.print("ENTER NO > ");
       Scanner keyboard = new Scanner(System.in);
       userVar = keyboard.nextInt(); //The given input stoted in userVar.
      // Now Apply Switch-case :)

} }