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

java exercice : strings variables and formatting

Challenge Task 1 of 3

Name.java
// I have setup a java.io.Console object for you named console

4 Answers

Hi Aladdin,

The question in the first task asks Define a string variable named firstName that stores your name. Set the value to your name.

For this you need to start with the data type (string), then the variable name (which we're given in the question) firstName. You then set that to equal your name by using the equals sign, then your name surrounded by double inverted commas, because it is a string. And don't forget the semi-colon. That all looks like:

String firstName = "Aladdin";

I hope that makes sense.

Steve.

Jeff Wilton
Jeff Wilton
16,646 Points

That comment is irrelevant to task 1, you just need to define a String called firstName and set it to your name.

// I have setup a java.io.Console object for you named console
String firstName = "Jeff";

On the next task, you will use the console object. :)

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

For your last challenge you need to store your name AND print it out :

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

thank you all

No problem! :+1: :smile: