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

Srikanth Nallagundla
PLUS
Srikanth Nallagundla
Courses Plus Student 231 Points

Not able to understand this error

Question :Print out to the screen using the printf method on console, "First name: " and the user's first name.

code :-- String Firstname = console.readLine("what is ur Fname" ); String firstname = "SRI"; console.printf("%s can code in java", Firstname ); console.printf("%s can code in java", firstname );

error: Oops! It looks like Task 1 is no longer passing.

Kindly help me in solving this

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String Firstname = console.readLine("what is ur Fname"  );
String firstname = "SRI";
console.printf("%s can code in java", Firstname );
console.printf("%s can code in java", firstname );
//String lastName = console.readLine("what is ur lname"  );
//console.printf("%s can code in java", lastName );

2 Answers

Jef Davis
Jef Davis
29,162 Points

The line String firstname = "SRI"; really shouldn't be there. It should look like the commented out lines on last name below that. And also remove the line console.printf("%s can code in java", firstname );

One other correction: String Firstname = console.readLine("what is ur Fname" ); should be String firstName to follow camelcase. The same goes for the line console.printf("%s can code in java", Firstname );

So, if you fix your code with the above recommendations, you will be taking the String firstName and assigning whatever value you type into the console with the readLine() method.

Your code should look more like this:

String firstName = console.readLine("what is ur Fname"); console.printf("%s can code in java", firstName);

Does that help?

// I have imported java.io.Console for you.  It is a variable called console.
String Firstname = console.readLine("what is ur Fname"  );
String firstname = "SRI";
console.printf("%s can code in java", Firstname );
console.printf("%s can code in java", firstname );
//String lastName = console.readLine("what is ur lname"  );
//console.printf("%s can code in java", lastName );

should be:

// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("First name:  ");
console.printf("%s can code in java!", firstName);
//String lastName = console.readLine("Last name:  ");
//console.printf("%s can code in java!", lastName);