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!

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 IO

[SOLVED] On challenge task 3 of 4 on the input section. They ask to print out the users first name using console.printf

The first 2 questions are for string first name and last name but i cannot do this third question I have gone back to the video but it doesn't explain why I'm getting an error

// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("What is your first name?");
String lastName = console.readLine("What is your last name?");
console.printf = ("My name is Dillon"FirstName);

Hello and welcome to the forums!

What the question is asking you to do is to take the input of String firstName and the input of String lastName and print them to the console.

console.readLine is an input function. The console will ask you "What is your first name?" and "What is your last name?". The input gets stored in firstName and lastName. Below is a correct version of the code.

String firstName = console.readLine ("What is your first name?");  //Console asks for your first name.
String lastName = console.readLine ("What is your last name?");   //Console asks for your last name.

console.printf ("My name is %s %s", firstName, secondName);  //Notice that there is no equals sign here.

The %s is to call the string and place it here. After the quotation marks, you put the name of the string that you want there with a comma in front and another comma after if you want another string. So the first %s will call up firstName and the second %s will call up lastName.

the end result will have the console print == "My name is John Doe"

Hope this helps!


This helped me understand thank you. This specific question is only asking for the first name therefore it should look like String firstName = console.readLine("What is your first name?"); String lastName = console.readLine("What is your last name?"); console.printf (" My name is %s", firstName); correct ? But is still telling me I have compiling errors

I figured it out it was console.printf (First name: %s", firstName");

I know you've solved this already, Dillon, but I just wanted to let you know that these challenges will sometimes not give you a completed task if you don't write exactly what they want you to write. Usually, they'll explicitly tell you to put whatever you want for a string if they're letting you do that but otherwise, it's best to just put whatever is in quotes.

Good luck, Dillon!

Just curious is it possible to make a gambling app or is that still illegal bc i have an idea that will blow up lol

Gambling programs themselves are not illegal in any state if you're using fake currency (as far as I'm aware). If you're using real money, on the other hand, you would need to go through some things to protect yourself, which is to do some research on which states it is illegal to do gambling, and then offer only restricted access/download which will go to people who reside within states where it is legal. This way when someone inevitably lies about where they live by selecting a download for the wrong state, you are not liable. There are likely far more issues with that, so I would do quite a bit of research on online gambling before going forth, Dillon, but I wish you the best of luck!

Marked as solved

1 Answer

im dont understand why it givs me this error even when i just copy and paste the code that should be correct ?

Bummer! Ensure your format string contains the required text "First name:".

Hey aleksander dahle,

The code that was used above, although perfectly valid and good practice, isn't the same code that is needed for the challenge. Be sure to look at exactly what the challenge asks of you. For example, if you only need the firstName variable for the task 3, you might just want to have only one %s placeholder instead of two and there's no need to pass in the lastName variable since it won't be used in that task. But it will be in the next one.