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

what i missed

what about my synex..

Equality.java
// 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 "hello"){
console.printf("first is equal to second");
}

2 Answers

andren
andren
28,558 Points

The syntax error stems from the fact that you don't have any parenthesis following the equals method. Whenever you are calling any method you have to use parenthesis, and when passing data into it that data has to go inside of those parenthesis.

On top of that there is another issue with your code. Which is the fact that you are not meant to manually type in the contents of secondExample in your code. You are meant to have Java compare them by simply referencing the variable itself. Like this:

String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if(firstExample.equals(secondExample)){ // Added parenthesis and changed "hello" to secondExample
console.printf("first is equal to second");
}

equals is a function.

// 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( "hello") ){

console.printf("first is equal to second");
}

Also they expect you to mention the variable name, rather then specifying the value of "secondExample" variable.