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

What does the "not a statement" error mean when compiling your java code mean?

When you compile code in java, and you have an error, it show you the error. One of the errors is "not a statement".

IO.java
String firstName = console.readLine ("What is your first name?") ;
String lastName = console.readLine ("What is your last name?");
  console.printf = ("First name %s"); firstName;
//The console.printf part has the error on it.

3 Answers

When forming a printf statement, the format is ("sentence with placeholders",objects to replace placeholders);

In other words, instead of closing the parentheses and separating "firstName" with a semicolon, simply place a comma after the quotes, then put firstName, and then close the parentheses.

console.printf("First name: %s",firstName);
Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Christina,

There are a few things wrong with the printf line:

  • console.printf is a method and cannot have an equal sign. As you have it, it's trying to assign the string as a variable to the method, which can't be done.

  • The firstName variable needs to be inside of the parenthesis in order for it to be attached to the placeholder.

  • You have a semi-colon where a comma should be.

Below is the correct line of code for you to review. I hope it makes sense. :)

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

Keep Coding! :dizzy:

line 3 you used firstName;. This not a statement even though it is well-dressed. Below is the code you need for the challenge, make sure you understand line 3 as I have fixed it. I assume you placed the firstName outside of the last closing parenthesis because it told you (when you use console.printf = (); it will not let you use the formatted %s properly and will show random errors).

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