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 trial

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.

Equality.java
// 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

saykin
saykin
9,835 Points

Hello!

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!