Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype String Equality

in my java basics Challenge Task 1 of 2 no matter how many times i try to type it. It continues to fail.

What is the right way to type it. I want to see if one of the ways I did it, if it was correct or not.

// I have imported a java.io.Console for you, it is named console. 
String first = "hello";
String second = "hello";
If (first.equalssecond("hello"));{
  console.printf("first is equal to second. \n\n");
String thirdExample = "HELLO";

1 Answer

9,835 Points


You seem to have some errors in your if statement. The If needs to be all lowercase, also to compare two strings, it's string.equals(string). You also don't need semicolon in an if statement, only on the code block inside the if statement.

While in the first task this will work, I would advice you to follow Java code convention and set your variables first, then execute the logic of your code. Right now you have the logic in between your variables.

Hope this helps, happy coding and don't be afraid to ask questions if you're stuck!