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

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,633 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,485 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: