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

Michelle Bramlett
Michelle Bramlett
1,253 Points

Console printf method

In the 3rd challenge of IO I have-

console.printf("First name:", Michelle);

It is saying that java doesn't recognize the capital M in my name? That is the only error listed. Any help? Am i missing something?

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("My name is Michelle.  ");
String lastName = console.readLine("My last name is Bramlett.  ");
console.printf("First name:",Michelle);

2 Answers

Elling Hauge
Elling Hauge
6,383 Points

In your first line you are using console.readLine to ask the user to enter something. In your code you a statment saying "My name is Michelle. " It would be better with , "My name is " and then the user enter his name. Same follows on line two.

On line three you are asking the console to print "First name:", Michelle. Michelle is not an variable. You should use one of the string variables you have created (line 1 and 2). Also you need to use a format spesifier where you want your variable placed. eg."First name: %s" the %s is your format spesifier telling the program that it should place a string variable in this spot.

Michelle Bramlett
Michelle Bramlett
1,253 Points

Hey Elling, Thank you so much for taking time to answer my question! I appreciate the help. Pretty foreign waters for me still:)

Elling Hauge
Elling Hauge
6,383 Points

No problem michelle. Did you solve the challenge ? if you have any questions don't hesitate to ask.

Michelle Bramlett
Michelle Bramlett
1,253 Points

Yes! I eventually got it ;) I still got stuck because I wasn't following the (" First name: %s\n" ....with a comma and firstName); Watched the next lesson after I figured that out and just like he said it would...puzzle pieces are starting to connect:) I can't wait until I look back at all of this and laugh at how easy it is:D Thanks again for making yourself available!