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 and Variables

benjamin wong
benjamin wong
498 Points

I'm following craig in his introductions.java After typing in same thing in workspace, my console displays only 1 print

import java.io.Console;

public class Introductions {

public static void main(String[] args) {
    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here
  String firstName = "Ben";
  console.printf ("Hello, my name is Ben);
  console.printf ("Ben is learning how to write java"/n);
}

}

How do i enable the console to print both printf 1 and 2?

1 Answer

Yanuar Prakoso
Yanuar Prakoso
15,196 Points

Hi Benjamin,

I think the problem lies in the way you wrote String inside the console.printf() you wrote:

console.printf ("Hello, my name is Ben);

console.printf ("Ben is learning how to write java"/n);

It should be:

console.printf ("Hello, my name is Ben");

console.printf ("Ben is learning how to write java\n");

If you want to use escape characters you use back-slash () not forward slash (/) and you write it inside the double quotes (" ").

also it will be much better if you write it:

console.printf ("Hello, my name is Ben\n");

console.printf ("Ben is learning how to write java\n");

since \n is an escape character that will make the output of the printf starts a new line before printing the second output:

I hope this will help

benjamin wong
benjamin wong
498 Points

Thanks for the clarification Yanuar!