Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Getting Started with Java IO

gerald greene
gerald greene
598 Points

Using the console's printf method, display a message that says, "First name: ", followed by the first name that the user

not sure why it is not accepting the code for this question in console? code looks exact same as previous lesson and workspace

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine ("what is your name?  ");
String lastName = console.readLine ("what is your last name?  ");
console.printf("my name is %s\n", firstName);

6 Answers

HI Gerald,

It is expecting the output to look a certain way -that's the test the compiler is looking to pass. So, the string output should look like "First name: ....", as the question says So your code should look more like:

String firstName = console.readLine("Enter your first name: ");
String lastName = console.readLine("Enter your last name: ");
console.printf("First name: %s", firstName);

Hope that helps,

Steve.

You need to output the following: First Name: your variable.. So your code should look like this:

  String firstName = console.readLine ("what is your name?  ");
  String lastName = console.readLine ("what is your last name?  ");
  console.printf("First name: %s", firstName);
  console.printf("Last name: %s", lastName);

console.printf("First name: %s", firstName); console.printf("Last name: %s", lastName);

//

String firstName = console.readLine("Ary"); String lastName = console.readLine("de Oliveira"); console.printf("First name: %s", firstName); console.printf("last name %s",lastName);

Bummer! Ensure your format string contains the required text "First name:".

Hi Fazal,

Did you get this sorted or do you still need some assistance? Here to help! :smile:

Steve.

gerald greene
gerald greene
598 Points

oh great, thanks very much for the super fast reply steve, greatly appreciated :)

Ger

No problem!

The challenges are quite specific as to what they expect.

Glad you got it sorted. :-)

Steve.