Java Java Basics Getting Started with Java IO

ofek Lalkin
ofek Lalkin
234 Points

task 3of io

// I have imported 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);
Long Nguyen
Long Nguyen
5,617 Points

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
21,818 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);