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

Hianoo Song
Hianoo Song
6,812 Points

printf

I'm having trouble with this question. I don't know why console.printf("<%s>",firstName); is incorrect for "check work". web workspace prints <firstName>.

Name.java
// I have setup a java.io.Console object for you named console
String firstName = "Hyunwoo";
console.printf("<%s>",firstName);

are the the signs "great than" "less than" needed?

Hianoo Song
Hianoo Song
6,812 Points

Turns out there is no need for 'greater than' and 'less than' signs. My bad.

1 Answer

Hi there,

You can simplify that still further as there's no need to interpolate into an empty string:

String firstName = "Hyunwoo";
console.printf(firstName); // no interpolation
console.printf("%s can code in Java!", firstName); // interpolation needed

So, you can print a string directly inside the printf method, but if you want to use a string's value inside another string, you use the formatter with the %s (for a string - numbers etc are slightly different).

I hope that helps,

Steve.

Hianoo Song
Hianoo Song
6,812 Points

I misunderstood the question. Thanks anyway~

As long as you got it sorted, that's great.

Steve.