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

nonunderstandable error

Import java.io.Console; Public Class Introductions {

Public Static void main(string[] args) { Console console= System.Console(); Console.printf("my name is %s",firstname); Console.printf("&s is learning java",firstname); string firstname="Cadceed"; } }

Name.java
// I have setup a java.io.Console object for you named console
Import java.io.Console;
Public Class Introductions {

Public Static void main(string[] args)
{
Console console= System.Console();
Console.printf("my name is %s",firstname);
Console.printf("&s is learning java",firstname);
string firstname="Cadceed";
}
}

2 Answers

Hi there,

I think firstly, we should point out that you aren't expected to add the import, create a class or the main method. The challenge provides you with a console object called console; you don't need to create that either.

Next up, there's some capitalisation going on that's not necessary. You've created a Console object, called it console then called printf on Console. As above, you just need to use the object provided which is called the same, console with a lowercase c.

The first part of the challenge asks for a String (uppercase S) object to be created with a value in it. You've got that; just uppercase the S and camelcase the variable name to be firstName:

String firstName = "Cadceed";

Next, you are asked to output a string from the console using printf. We don't use the formatters yet, just output the string:

console.printf("Cadceed can code in Java!");

Again, lowercase c on console.

Next, we use the formatter to interpolate the firstName variable inside the output string. As Jonathan said, use %s for this.

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

So, you end up with two or three lines of code only to complete this challenge:

String firstName = "Cadceed";
console.printf("Cadceed can code in Java!"); // you can delete this line if you want
console.printf("%s can code in Java!", firstName);

I hope that helps get you through the challenge. Have a look at the words you've capitalised, however. In languages like C++ there's lots of capitalising. Not so much in Java! So keywords like public, private, class and import have lowercase initial letters. Whilst not necessary for this challenge, it's worth noting for the future.

Steve.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi there,

There's a few problems I can see.

You need to declare and assign your variables before you reference them, otherwise Java doesn't know what value it is looking for.

Also there's an incorrect format specifier. Try %s, instead of &s

// I have setup a java.io.Console object for you named console
Import java.io.Console;
Public Class Introductions {

string firstname="Cadceed";

Public Static void main(string[] args) {
      Console console= System.Console();
      Console.printf("my name is %s", firstname);
      Console.printf("%s is learning java", firstname);

  }
}

Good luck!

Helpful really! Thannks jonathan