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 trialMelina Ortiz
958 PointsI dont know what im doing wrong
I can't see what happen the code is not working
// I have setup a java.io.Console object for you named console
String firstName = "Melina";
console.printf (" %S can code in java, firstName");
3 Answers
Alexander Davison
65,469 PointsTry putting the ", firstName" part of the string outside and next to the string. Code challenges are also very picky, so if you include a space in the end of a string then the challenge won't let you pass.
A couple errors:
- You have an extra space in the beginning of your string.
- Try changing the "%S" (Java is super picky about cases!) to "%s".
- You said "java" try changing it to "Java" (I think you know why)
Take a look at these:
This is your code
// I have setup a java.io.Console object for you named console
String firstName = "Melina";
console.printf (" %S can code in java, firstName");
This is the code that actually would work:
// I have setup a java.io.Console object for you named console
String firstName = "Melina";
console.printf("%s can code in Java", firstName);
Good luck and I hope this helps! ~Alex
EDITED
Brendon Butler
4,254 PointsThe printf()
function takes multiple parameters. Each parameter should be separated by a comma. In the snippit you posted, your comma is within the quotations. (Quotations define a String in Java).
console.printf ("%S can code in java, firstName");
// should be this
console.printf("%s can code in java", firstName);
Alexander Davison
65,469 PointsNice one, Brendon! However there's a couple more mistakes. Take a look here:
- "java" should be "Java"
- There's an extra space in the beginning of her string.
These are required because code challenges are especially picky and also Java is picky.
Good luck
EDITED
Brendon Butler
4,254 Points... I just copied her code
Also, it shouldnt be Console.. It should be console.
Alexander Davison
65,469 PointsOh, whatever lol I'm new to Java and I'm too used to C#.
Thanks for telling me!
Brendon Butler
4,254 PointsUnderstandable. I dont know C#, but in java, static class variables and methods can be referenced using the capital class name.
public class Hello {
public static void world() {
// do stuff
}
publid static void world2() {
// do stuff
}
}
public class Other {
public void otherMethod() {
// you can access the world method either way
Hello.world();
Hello hello = new Hello();
hello.world();
// the only way to access the world2 is from a variable of the Hello type
hello.world2();
}
}
In the challenge, they say this "I have setup a java.io.Console object for you named console" so you would use the variable console
to access its methods.
Alexander Davison
65,469 PointsCool.
(lol inside of me im all confused...)
Melina Ortiz
958 PointsThanks so much! I see I have tons of questions!
Alexander Davison
65,469 PointsYour pleasure :)