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 trialmustafa bayer
39 PointsIf I write the program correctly, it gives an error, can you help?
If I write the program correctly, it gives an error, can you help?
// I have setup a java.io.Console object for you named console
String firstName = "Mustafa";
console.printf("YOUR NAME is %s", firstName);
4 Answers
Paolo Scamardella
24,828 PointsHaven't touched Java in awhile; however, I believe there is no such thing as a function called printf on a console object. I think the task description is a little misleading. You need to use System.out.printf.
String firstName = "Your Name Goes Here";
System.out.printf("%s can code in Java", firstName);
Stephen McBride
7,769 PointsHi Mustafa
I think your problem is what you're printing. In the challenge it is asking you to print out "Mustafa can code in Java!".
When your code is run it prints out "YOUR NAME is Mustafa".
to fix this just change your printf to-
console.printf("%s can code in Java!", firstName);
Daniel Marin
8,021 PointsIn the test it says that java.io.Console is already imported So it works as Mustafa typed the only problem is the output.
String firstName = "Mustafa";
console.printf("%s can code in Java!", firstName);
So it needs to output "Mustafa can code in Java!" otherwise it fails.
Hoessein Abd
Python Web Development Techdegree Graduate 19,107 PointsThere's nothing wrong with your Syntax. You're just not passing the correct instructions from the challenge to the printf method. You have to print to the console. "<YOUR NAME> can code in Java". <YOUR NAME> in this case means place the string firstName to <YOUR NAME>. So the console says: Mustafa can write in Java.
Hope that helps to complete this challenge.