Java Java Basics Getting Started with Java Receiving Input

Why am I receiving an error when compiling?

This is the error I'm receiving.

Introductions.java:8: error: cannot find symbol
String firstName = console.readLine("What is your name? ");
^
symbol: variable console
location: class Introductions

This is what my source code looks like.

public class Introductions {

public static void main(String[] args) { String firstName = console.readLine("What is your name? "); Console console = System.console(); console.printf("Hello, my name is %s\n", firstName); console.printf("%s is learning how to write Java.\n", firstName); }

}

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 50,875 Points
Console console = System.console();

should go before

String firstName = console.readLine("What is your name? ");

otherwise you are attempting to use variable console before it is declared