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

Harishkumar Lohar
Harishkumar Lohar
33 Points

cant understand where the problem is hidden

cant understand the Error please explain

Name.java
// I have setup a java.io.Console object for you named console
{
Console console = System.console ();
string firstname = "Harry";
Console.print ("%s lernt von anfang an\n", firstname);
Console.print ("%s lernt wie soll JAVA screiben\n", firstname);
}

1 Answer

Richard Lambert
PLUS
Richard Lambert
Courses Plus Student 7,180 Points

Hello mate,

  1. For this exercise, an instance of the Console class has been created for you and is referenced by the variable console; no need to declare it yourself.
  2. The Console class has the method printf(String fmt, Object... args), used for writing a formatted string to the console's output stream. Looking at the documentation, you will see that the Console class has no print() method.
  3. printf(String fmt, Object... args) is non-static and needs to be called on the object instance, console, and not Console.
  4. No need for the opening and closing braces.
Name.java
// I have setup a java.io.Console object for you named console
{    // (4)
Console console = System.console ();    // (1)
string firstname = "Harry";
Console.print ("%s lernt von anfang an\n", firstname);    // (2)(3)
Console.print ("%s lernt wie soll JAVA screiben\n", firstname);    // (2)(3)
}    // (4)   

Hope this helps