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

Am I adding too much?

What did I do wrong?

Equality.java
// I have imported a java.io.Console for you, it is named console. 
String firstExample = console.readLine("hello");
String secondExample = console.readLine("hello");
String thirdExample = console.readLine("HELLO");
if (firstExample.equals(secondExample)) {
  console.printf("%s", thirdExample);

2 Answers

jacksonpranica
jacksonpranica
17,610 Points

Hey Michael,

First off, you're printing off the variable thirdExample when the challenge tells you what string you should be printing. So read the challenge description and look what you're suppose to be printing.

Secondly make sure to close your if statement with "}"

I'm very new to this, can you break that done a little more. I went back and added the missing bracket but I'm still getting errors. I even changed my "printf" statement. I'm really lost..

jacksonpranica
jacksonpranica
17,610 Points

Hey Michael,

Don't worry about being new, I should have done a better job breaking it down from the start.

Here is what I mean. Your if statement is wonderful. You did everything correctly. the problem is whats being printed.

if (firstExample.equals(secondExample)) {
  console.printf("first is equal to second");
}

It says in the description to print out "first is equal to second", so that is what you need to be printing in the printf statement like above.

Try to use this as a base to finish the challenge with the second if statement

Oh, ok I see. I was kinda jumping the gun a bit huh? Thank you very much for your help.

jacksonpranica
jacksonpranica
17,610 Points

No problem Michael! Hopefully that cleared things up. If it didn't I apologize.