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 Objects (Retired) Meet Objects Refresher

equals question in java

just a little confused on this trying to get them to equal. can someone help with this i know its right there in front of me.

thanks

justin

int weightCraig = 160;
int weightMonty = 130;
if (weightMonty            weightCraig) {
    console.printf("Whoa that's a huge dog!");

3 Answers

Devin Scheu
Devin Scheu
66,191 Points

Hey Justin,

All you did was forget the greater than symbol, your code should look like this:

int weightCraig = 160;
int weightMonty = 130;

if (weightMonty > weightCraig) {
    console.printf("Whoa that's a huge dog!");
}

Edit: for this Quiz, it is asking what comparison operator to use to check if Monty's weight is greater than Craig's weight.

int weightCraig = 160;
int weightMonty = 130;

if (weightMonty > weightCraig) // true; 160 is greater than 130

Edit: the rest of this is not related to the quiz but still useful in regards to comparing strings

if ('foo'.equals('foo')) // true

// or

if ('Foo'.equalsIgnoreCase('foo')) // true

java is odd when using == for string comparison, because it is checking if those objects are the same, not if they contain the same value.

String str1 = 'bacon';
String str2 = 'bacon';

if (str1 == str2) // false; str1 is not the same object as str2

if (str1.equals(str2)) // true

thanks for the clarification Robert. Anything helps, i understand everything i was just wondering for the code

If (weightMonty > weightCraig) // true 160 is greater than 130

this part is confusing to me because im looking at it like weightMonty is greater than weightCraig because of the symbol >.

how you can > sign weightmonty is less then weightcraig

And it's read left to right.

My Best answer >