Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Getting Started with Java Strings, Variables, and Formatting

firstName String exercise issue

I am trying to complete the exercise for the "firstName" String and it keeps failing. I actually cut and pasted out of the workspace (where it works) and it is not working in the exercise. Other than the errors it is showing the issues, what can I do to see what is missing from the code?

Name.java
// I have setup a java.io.Console object for you named console
public class FirstNameExercise {

     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 %s\n", firstName);
       console.printf("%s is learning to write in Java\n", firstName);

  }
}

2 Answers

andren
andren
28,538 Points

You are not missing anything in your code, quite the opposite. For most of the basic challenges you don't have to type any boilerplate code. In other words no code other than the specific lines of code the challenge asks for. Things like creating a class and importing the Console is done automatically behind the scenes.

So for the first exercise which asks you to define a String variable that contains your name, you only need one line of code which does exactly that one thing.

Like this:

String firstName = "Ben";

That is the only code needed to pass the first task of this challenge.

Thanks. I thought I did that the first time and it replied Bummer- its wrong.