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

print firstName plus can code in java to console

I've typed console.printf(firstName "can code in Java!"); but I'm getting a cummer compiler error.

Name.java
// I have setup a java.io.Console object for you named console
String firstName= "tamara";
console.printf(firstName %s, "can code in Java!");

2 Answers

Daniel Szepanski
PLUS
Daniel Szepanski
Courses Plus Student 5,098 Points

Hi, you have to turn around your code like this, it should work.

// I have setup a java.io.Console object for you named console
String firstName= "tamara";
console.printf("%s can code in Java!" , firstName);
Felix Sonnenholzer
Felix Sonnenholzer
14,654 Points

Like Daniel said it works if you change the order.

The important thing is, that %s is part of the String you want to print. %s is just a placeholder for the additional parameter you provide. You can also use %s multiple times, but you have to provide enough arguments.

String firstName = "Felix";
String lastName = "Sonnenholzer";

console.printf("My first name is %s and my last name is %s", firstName, lastName);

The first %s gets replaced by the first parameter and the second %s by the second and so on.