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

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,558 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.