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 trialMohammad Saeed
Courses Plus Student 315 Pointsi wrote if (firstExample.equals(secondExample)) { //wrote the rest of the block right } What am i doing wrong here?
It says try again, but is my code correct?
// I have imported a java.io.Console for you, it is named console.
String firstExample = "hello";
String secondExample = "hello";
if (firstExample.equals(secondExample)) {
console.printf("first is equal to second\n");
System.exit(0);
}
String thirdExample = "HELLO";
2 Answers
Jennifer Nordell
Treehouse TeacherAll you need to do is remove this line:
System.exit(0);
Jeremy Hill
29,567 PointsI just did the challenge and passed the first task with this 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(secondExample))
console.printf("first is equal to second");
Jeremy Hill
29,567 PointsYes, most of the time you just add specifically what you are told to. It usually gives you a hint whether it is the compiler throwing the error or the challenge just telling you that the code/answer received isn't what was expected.
Mohammad Saeed
Courses Plus Student 315 PointsMohammad Saeed
Courses Plus Student 315 PointsThank you that worked! But what i don't get is, in the tutorial it was instructed to place System.exit(0); afterwards. So i'm guess because it wasn't instructed to automatically exit the program that isn't needed then?
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherMohammed Saeed Keep in mind that challenges are a little special. They have to be able to evaluate your code. My guess is here that if the system exits... well... they can't evaluate it anymore.
It's a good idea (inside of challenges) to never do anything they don't explicitly ask for. Try not to implement variables they don't want etc. Even though the code may be fully functional outside the challenge, it can cause the challenge to fail.