Java Java Basics Getting Started with Java Strings, Variables, and Formatting

Not able to figure out why I am getting the error "illegal start of expression"

Its throwing the same error again and again "illegal start of expression". Please refer the attachment and help me to get this fixed. Thanks

Name.java
public class Name {
  public void main(String[] args){
    Console console1 = System.console1();
    String firstName = "Anoop";
    console1.printf("%s can code Java ", firstName);
  }
}

2 Answers

Stefan Tihan
Stefan Tihan
22,541 Points

Try the following solution

String firstName = "Anoop";
console.printf("%s can code in Java", firstName);

P.S.: The console is already defined !

Thanks Stefan....but still I am getting the same error. This is my code and as suggested by you, I have made the changes but the same error. When I tried in eclipse it shows null pointer exception.

public class Name { public void main(String[] args){ Console console = System.console();

String firstName = "Anoop";

console.printf("%s can code in Java", firstName); } }