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 Strings, Variables, and Formatting

I need some help with 2 second task. I am not clear on what the text is.

Can someone help?

Name.java
String firstName = ("Brendan");
console printf = ("%s can code in Java!");

2 Answers

String firstName = ("Brendan"); console printf = ("%s can code in Java!");

change it so the string firstName is included, like this

String firstName = ("Brendan"); console printf = ("%s can code in Java!", firstName);

I am so sorry, I forgot to mention that there is an error in your script, it is console.printf and not console printf

and there is not an equal sign in between console.printf and the statement

Console is capitalized and is a library that you have to import at the top of your file and instantiate it if you want to use it. As in:

import java.io.Console;

public class MyApp{
Console console = System.console();
}

Also, you're accessing the "printf" method of Console, so you don't use the "=" sign, you just pass it your string as an argument. As in:

console.printf("Here's my text string.");

Third, if you want to format a string with a variable, you'll pass them both in as arguments like so:

console.printf("%s is my name", myStringVariable);

If you want to avoid all that stuff, I suggest just using the System.printf() method, rather than Console:

System.printf("%s is my name", myStringVariable);

You also don't need to put parentheses around your variable declarations. This will do:

String myStringVariable = "my string";