Issue
When running this code;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to Bank of America");
System.out.println("Input your name;");
String name = scanner.nextLine();
System.out.println("Hello there "+name);
}
}
I receive the following error message;
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
scanner cannot be resolved
at Main.main(Main.java:7)
I've already searched online for solutions, and none of them work for me. Most of them show examples where a ´;´ is missing, or it wasn't imported, or that the JDK was out of date. I've already imported java.util.Scanner, my JDK and version of Eclipse are up to date, I mean I installed them all 5 hours ago, I don't understand what the problem is or how to begin resolving it. I'm working with the Eclipse IDE 2023-03 and jdk-20.
Solution
The Scanner reference is named input (not scanner). Change
String name = scanner.nextLine();
to
String name = input.nextLine();
Or, change
Scanner input = new Scanner(System.in);
to
Scanner scanner = new Scanner(System.in);
Answered By - Elliott Frisch
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.