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

why is this console console printf "my name can code in Java"; not working

console console printf "my name can code in Java";

Name.java
// I have setup a java.io.Console object for you named console
String String = firstName;
  firstName = "Eric";
   console console printf "Eric JOhansen can code in Java";
Ryan Jin
Ryan Jin
15,337 Points

If you are using the workspace here at Treehouse. You can use console.printf. However, if you using another development tool installed on your own computer, you can't use the console. Instead, you can only do System.out.println("Eric Johanson can code in Java");

12 Answers

Eric Johansen - If you check on the text editor of the challenge it notes "I have setup a java.io.Console object for you named console" so you basically don't need to import console as it is already set up.

In the 1st step it says you should define a string for the first name. Which is this part of your code.

String firstName = "Eric"; 

on the 2nd step it asks you to call the printf method on console inputting a given statement in it. There you have written

check.printf(firstName can write in java); 

but that is wrong because you are not calling printf method on console. You are calling it on check. As I said in the beginning it has already imported console for you so it expects you to use that. Also what you are passing on to printf method is a string with a variable. To pass on a string you need double quotes "" also instead of firstName it expects you to write your actual name which is Eric.

Lastly on the 3rd task... To create a string placeholder you'll need %s. You might like to check on the video on how to do that. So the structure of it suppose to look like

console.printf("Add something in here and don't forget to use a placeholder+its variable somewhere in the parenthesis"); 

Also pay attention it is asking you to print "<YOUR NAME> can code in Java!" and not "firstName can write in java" that too can come off as an error as you are not writing what it is asking from you.

I hope this helps you figure it out. Try to read it step by step, if you are still stuck update us with your new code so we can help. Good luck.

Allan Clark
Allan Clark
10,810 Points

Missing just a little bit of syntax here. The console object needs to be created before we can call the printf method on that object.

Console console = System.console();
// the second "console" is a variable name so it can be anything

From there we are able to use the console object and its methods.

console.printf("Han shot first");

console console = System.console(); String string = firstName; firstName = "Eric";

This is still not working

Allan Clark
Allan Clark
10,810 Points

The first console has to be capital because it is declaring the class of the object and Java is case sensitive. Also the string variable holding the firstName variable is unnecessary, and the firstName variable needs its type. DRY

try this:

Console console = System.console();
String firstName = "Eric";

console.printf(firstName);

of course edit the printf argument to fit your challenge.

Allan Clark
Allan Clark
10,810 Points

The importing and java console stuff is all abstracted out for you in this challenge all you need is:

String firstName = "Allan";
console.printf("%s can code in Java
Allan Clark
Allan Clark
10,810 Points

You do not need the import or public class Name{ public static void main(String[] args) part. that is all done. This code got me past the challenge:

// I have setup a java.io.Console object for you named console
String firstName = "Allan";
console.printf("%s can code in Java", firstName);
Daniel Cunningham
Daniel Cunningham
21,109 Points

console.printf("Eric JOhansen can code in Java");

you're missing the period between "console" and "printf". You should also put your quote in parenthesis and make sure you end with a semi-colon.

thanks

public static void.main(String[] args);

Console Console = System.console(); String String = firstName; firstName = "Eric"; Console.PrintF("Eric");

This is not working either.

Daniel Cunningham
Daniel Cunningham
21,109 Points

Console console = System.console(); <br> String string firstName; <br> firstName = "Eric"; <br> console.printf("Eric"); <br>

Java is case sensitive. You need to capitalize the first "Console" but the second word "console" is a variable declaration (do not capitalize the first word in a variable declaration). the same thing happens with String. The first "String" is invoking the string class and the next word should be your variable ('firstName'). You do not need to say string twice.

do not use any capital letters on "console.printf("Eric");". You are calling the variable console, and the function printf (which has no caps) on the object.

JavaTester.java:68: error: cannot find symbol Console console = System.console(); ^ symbol: class Console location: class JavaTester JavaTester.java:68: error: variable console is already defined in method run() Console console = System.console(); ^ 2 errors I ran the code below and I got the error above. Why doesn't it run right?

Console console = System.console(); String firstName = "Eric";

console.printf(firstName);

Allan Clark
Allan Clark
10,810 Points

That error makes it sound like the Console console = System.console(); part may not be needed. The TreeHouse workspace has certain stuff already done for you. I see now. Yeah the console object is already made for you so just take that part out. the challenge should look like this.

// I have setup a java.io.Console object for you named console
String firstName = "Allan";
console.printf("%s can code in Java", firstName);

Console console = System.console(); String firstName = "Eric"; Console.printf("firstName");

I have taken that advice given by the forum but this still won't run.

Daniel Cunningham
Daniel Cunningham
21,109 Points

Is the code at the top your entire code or are there class declarations in front of it?

it is the only code I have. I am trying to work through the beginners package in treehouse. This is the only code I have and I can't make this happen. I appreciate your help.

Daniel Cunningham
Daniel Cunningham
21,109 Points

<br>import java.io.Console; <br> public class Name {
<br> public static void main(String[] args) { <br> Console check = System.console(); String firstName = "Eric"; check.printf(firstName); } }

Daniel Cunningham
Daniel Cunningham
21,109 Points

First, You have to use the initial code of "import java.io.Console"

Then you need to declare a public class with a name that matches your file name... in your case, it is "public class Name". <br>

use curly brackets to enclose the remaining code. <br>

enter "public static void main(String[] args)" and enclose additional code in curly brackets <br>

enter the code and close the brackets.

import java.io.Console; public class Name{ public static void main(String[] args){ Console check = System.console(); String firstName = "Eric"; check.printf(firstName can write in java); }}

I still am having any luck with this code.