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 trialUnsubscribed User
7,386 PointsAdd an if statement that checks to see if firstExample is equal to secondExample. If it is, print out "first is equal to
I tried typing "hello" the first time but that didn't work either. Help please.
// I have imported a java.io.Console for you, itis named console.
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if (firstExample.equalsIgnoreCase ("secondExample")) {
console.printf("first is equal to second. \n");
system.exit(0);
}
4 Answers
Ethan M
10,637 PointsThe conditional statement is expecting firstExample to equal literally "secondExample" you set the variable in a set of strings therefore it'll be expecting that. FIx
// I have imported a java.io.Console for you, itis named console.
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if (firstExample.equalsIgnoreCase (secondExample)) {
console.printf("first is equal to second. \n");
system.exit(0);
}
If you have no strings in the parentheses then it will know that your talking about the string secondExample as opposed to literally expecting secondExample as the value of firstExample.
To be specific if you didn't have the set of strings on secondExample it will now replace secondExample with
if (firstExample.equalsIgnoreCase ("hello")) {
console.printf("first is equal to second. \n");
system.exit(0);
}
Damion Samuels
7,624 Pointsif (firstExample.equals(secondExample)) { console.printf("first is equal to second"); }
Unsubscribed User
7,386 PointsI thank you for your time however, it still shows as incorrect according to the automated system. // 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(secondExample)) { console.printf("first is equal to second. \n"); system.exit(0); }
Ethan M
10,637 Pointssystem.exit(0) is not needed :)
Thomas Salai
4,964 PointsWhat wrong with my code here.?
// 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");
}
I got an error.
Bummer! There is a compiler error. Please click on preview to view your syntax errors!
Thomas Salai
4,964 PointsI found the syntax error.. in if statement.. I forgot the end ")".