Java Java Basics Getting Started with Java Receiving Input

Raslan Ismail
Raslan Ismail
10,261 Points

i can't compile my code

import java.io.Console;

public class Introductions {

public static void main(String[] args) {
    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here
  String firstName=console.readline("what is your name?  ");
    console.printf("hello, my name is %s\n",firstName);
  console.printf("%s is learning how to java\n",firstName);

}

}

Introductions.java:8: error: incompatible types: String cannot be converted to boolean
String firstName=console.readline("what is your name? ");
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

1 Answer

Amir Yousef
Amir Yousef
1,761 Points

Raslan,

The problem here is "readline" without the upper case L is not considered as a method for the compiler.

Please change: String firstName = console.readline("what is your name? ");

To: String firstName = console.readLine("what is your name? ");

It will work.

I already tested the code as:

import java.io.Console; public class Introductions { public static void main(String[] args) { Console console = System.console(); // Welcome to the Introductions program! Your code goes below here String firstName = console.readLine("what is your name? "); console.printf("hello, my name is %s\n", firstName); console.printf("%s is learning how to java\n", firstName); } }

And it worked.

Hope this will help you, Amir