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

ofek Lalkin
ofek Lalkin
2,770 Points

task 3of io

help!

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName= console.readLine("My Name Is Ofek");
String lastName= console.readLine("My Name Is Lalkin");
console.printf(" first Name");
console.printf("first Name is %S",firstName);

It looks like its reading the first printf statement and is catching an error because it doesn't have the firstName variable. Your second printf statement is correct. If you delete the first printf statement, your code will compile.

1 Answer

Rich Zimmerman
Rich Zimmerman
24,063 Points

The console.readLine() method will take input from the user in the command line. It looks like the way you're trying to use it is as if it's reading "My Name is Ofek", but that is not correct. the readLine method print out whatever is in the quotes and then store the user's input in the variable to be used.

For examples:

String firstName = console.readLine("What is your first name? ");

This will print "What is your first name? " to the console, at which point you can type "Ofek". Then when you reference the variable 'firstName', is has the value of "Ofek".

Another possible error - in your printf() you've got "%S", should be a lower case s.

console.printf("first Name is %s", firstName);