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

I am having problems with a symbol error

I don't have any idea what I am doing wrong here is the code: ~ // I have imported a java.io.Console for you, it is named console. String firstExample = "hello"; String secondExample = "hello"; String thirdExample = "HELLO"; int first = Integer.parsInt(firstExample); int second = Integer.parsInt(secondExample); int third = Integer.parsInt(thirdExample); if (first = second) { console.printf("first is equal to second.\n"); System.exit(0); } ~

Equality.java
// I have imported a java.io.Console for you, it is named console. 
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
int first = Integer.parsInt(firstExample);
int second = Integer.parsInt(secondExample);
int third = Integer.parsInt(thirdExample);
if (first = second) {
  console.printf("first is equal to second.\n");
  System.exit(0);
}

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey John,

I feel you may have misinterpreted the instructions and have gone way beyond what the task is asking for and are using some methods that are not asked for and not even needed. ?

First, you have created 3 new variables that were not asked for, and also you're declaring them as ints and then using parseInt(). But there are no integers in this question at all, only Strings. ??
So those three lines need to be deleted.

Second, your if statement is close, but there is a syntax error (and a naming error now that those un-needed variables have been deleted. The syntax error is in the comparison. You are using a single equal sign, which is an assignment operator. You need to be using the comparison operator which is the double equal sign (==). Also, now the variable names need to be corrected. The instructions ask you to compare firstExample and secondExample, so you'll need to change the names accordingly.

Finally, the instructions didn't ask for the System.exit() method to be called, so... needs to be deleted.

One very important thing to remember is that Challenges are very picky and very strict. If you add something that wasn't asked for... deleted/change something that was preloaded without being told to... even a spelling or grammatical error will almost always result in a Bummer!. So, in short, if the instructions don't say to do it... don't.

Below is the corrected and passing code for Task One. Have a look and see what I mean by the above notes:

String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";

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

Keep Coding! :) :dizzy:

I really appreciate the prompt answer, Jason. I have spent all afternoon working on this and I've actually used '==' before but forgot in this case.. Your detailed response was perfect and I really appreciate the time you put into this.