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

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Hanns,

welcome to the coolest java forum on the planet :)

The printf function prints a formatted text to the console or inside an IDE (like IntellyJ or Eclipse). To use the printf() function you will need formatters.

  • This are %s for Strings that you will use a lot in the course:
String name = "Hanns";
// you create a String variable that represents your name
System.out.printf("my name is %s", name);
// where you place the %s (String formatter) formatter there will be your "name"

There are formatters not only for String, but for numbers, chars, floats and more ...

See here:


And in the challenges you will see this code:

console.printf("my name is %s", name);
// this is the same as above but using the console object for printing text

I hope I could help a little