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 trialRiya Prasannan
806 PointsequalsIgnoreCase
String firstExample = "hello"; String secondExample = "hello"; String thirdExample = "HELLO"; if(firstExample.equalsIgnoreCase("HELLO")) { console.printf("First and third are the same ignoring case"); }
Not able to understand what is wrong in this.
// I have imported a java.io.Console for you, it is named console.
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if(firstExample.equalsIgnoreCase("HELLO"))
{
console.printf("First and third are the same ignoring case");
}
2 Answers
Wil Arter
1,422 PointsRiya,
if(firstExample.equalsIgnoreCase(thirdExample)){
console.printf("first and third are the same ignoring case");
}
The above worked, the task says to compare the firstExample to the thirdExample variable however in your answer you are not comparing these, you are comparing the firstExample to a string of "HELLO" instead of the variable thirdExample, hope this helps.
Steve Hunter
57,712 PointsHi there,
Just to add, you need to keep the first task's if
statement in place else this will fail the challenge. The second task asks for another if
statement so just add to the bottom of your code:
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");
}
Steve.
Riya Prasannan
806 PointsHi Arter and Steve, I tried the below code again and its working now. Not sure what happened when I tried earlier. if(firstExample.equalsIgnoreCase(thirdExample))
Appreciate the help and quick reply. Thanks.
Riya Prasannan
806 PointsRiya Prasannan
806 PointsI tried this too, but it wasnt working