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 Using Logical ORs and ANDs

Dima Nicholson
Dima Nicholson
809 Points

Logical conjunction

I don't think one of your questions in quiz has correct answer. The question is: "Assuming that Sara has taken the Java and Python tracks, what is the value of isFamiliar below: boolean isFamiliar = (learnedJava || learnedPython || learnedRuby);". Your answer is True. But Sara has taken the Java && Python tracks, not Java || Python. isFamiliar will be true if it equals to (learnedJava && learnedPython || learnedJava || learnedPython || learnedRuby).

1 Answer

// in this example there are 2 main operators, && and ||

// For the following code only 1 has to be true and it will return true. It does not matter if she has learned 1, 2 or all 3 of them
boolean isFamiliar = (learnedJava || learnedPython || learnedRuby); // <----------------true

//While using the && operator, all of the arguments have to be true and since she does not know Ruby, it is false

boolean isFamiliar = (learnedJava && learnedPython && learnedRuby); // <--------------false