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

im so stuck

i dont get where i messed up

IO.java
String firstName = console.readLine("Solomon");
String lastName = console.readLine("Fields");
String Solomon = console.printf("firstName");

1 Answer

Tristan Smith
Tristan Smith
3,171 Points

Hi Solomon,

Don't worry, this can happen to all of us. It looks like you're creating a String variable from console.printf, which you can't do. You may be getting a incompatible types error similar to this.

 error: incompatible types: void cannot be converted to String

Be sure to follow the instructions carefully, you won't be creating a variable for the last two tasks. It wants you to print the values of the variables you created. For this challenge, console.printf requires a few things which are noted in the videos preceding it, please re-watch them to get a more in-depth explanation. [1] It starts around the 3 minute mark.

You can print a string to the console like so

console.printf("Hello there");

Or you can print strings and variables

// %s is for String
// %d is for digit

String myName = "Tristan";
console.printf("Hi my name is %s.",myName);

Here's a doc that shows more info on the types [2]

You'll place the %s or %d where you want the value of the variable to show when it's printed. My example above will look like this

Hi my name is Tristan.

If I put the %s at the beginning, it may not make sense, but it will work.

String myName = "Tristan";
console.printf("%s Hi my name is.",myName);

The output would be

Tristan Hi my name is.

I hope that helps. If you come across issues like this, the solution is usually in the videos. When I took this track I re-watched them several times, it helped a ton.

[1] https://teamtreehouse.com/library/java-basics/getting-started-with-java/strings-and-variables

[2] https://en.wikipedia.org/wiki/Printf_format_string#Type_field

Tristan Smith
Tristan Smith
3,171 Points

Also be sure to check the error messages and post them here, it can help us help you. :-)