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 trialBrendan Freitas
97 PointsI need some help with 2 second task. I am not clear on what the text is.
Can someone help?
String firstName = ("Brendan");
console printf = ("%s can code in Java!");
2 Answers
Will Long
5,449 PointsString 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);
karis hutcheson
7,036 PointsConsole 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";
Will Long
5,449 PointsWill Long
5,449 PointsI am so sorry, I forgot to mention that there is an error in your script, it is console.printf and not console printf
Will Long
5,449 PointsWill Long
5,449 Pointsand there is not an equal sign in between console.printf and the statement