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

oliver sarmiento
oliver sarmiento
121 Points

Define String variable firstName that stores your name. Unable to compile

public class Name { public static void main(String[] Args) { Console console = System.console(); String firstName = "Oliver"; console.printf("Hello" + firstName); } }

Name.java
public class Name {
  public static void main(String[] Args) {
    Console console = System.console();
    String firstName = "Oliver";
    console.printf("Hello" + firstName);
  }
}// I have setup a java.io.Console object for you named console

2 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey Oliver, we don't need to set up a console object, the comment already let us know that this was set up.

Second, when you are using print f you don't need to use the to concatenate the string with the addition sign.

All that is needed is to declare your variable then pass in the value like below

console.printf("%s can code in Java!", firstName);

HI Oliver,

You've done that correctly, but added all the other stuff that the compiler isn't looking for. It literally just wants the one line:

String firstName = "Oliver";

:wink: :+1:

Steve.