Java Java Basics Perfecting the Prototype String Equality

Frank Randol
Frank Randol
234 Points

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,820 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!