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 trialsahil jagdale
Courses Plus Student 596 Pointswhat am i missing?
it says try again..is this a valid code?
// I have imported a java.io.Console for you, it is named console.
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if ( firstExample.equals("hello")) {
if (secondExample.equals("hello")) {
console.printf("first is equal to second ");
System.exit(0);
}
}
2 Answers
Daniel Babbev
10,354 PointsYou have to use the variable's name as an argument in equals() and equalsIgnoreCase() methods. The correct code looks like:
// I have imported a java.io.Console for you, it is named console.
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if(firstExample.equals(secondExample)){
console.printf("first is equal to second");
}
if(firstExample.equalsIgnoreCase(thirdExample)){
console.printf("first and third are the same ignoring case");
}
Kym Bryan Carasig
Courses Plus Student 1,013 Pointsconsole.printf("first is equal to second ");
this code right here bud, you used printf even though you dont use any variable with your set of strings. I mean like this. (Sorry, as English isn't my native language. Can't explain very good.)
console.printf("My name is %s", name);
you can use println or just print if you just wanted to print set of words/strings, like this
console.println("first is equal to second");
or
console.print("first is equal to second");