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 Meet Objects Welcome Back

Richard Carrera
Richard Carrera
1,342 Points

So basically depending on what you type "||" or will always print out true while && will print false?

A lil confuse on the operators :/

2 Answers

Ronald Williams
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ronald Williams
Java Web Development Techdegree Graduate 25,021 Points

Hello Richard, it depends. Let's say you have two boolean variables: boolean a; boolean b;

Rules for &&: a && b is true if both a = true and b = true. a && b is false if either is false.

Rules for ||: a || b is false if both a = false and b = false. If either a or b is true, then a || b is true.

Just remember that || is asking "or" and && is "and" obviously. So to be true with || you only need one to be true.

An example would be someone needing (photoID || birthCertificate) If you have either one then true, you don't need both, but if you don't have photoID or birthCertificate then false.

If you need (photoID && birthCertificate) then you need both to get true. If you only have one or the other then you get false.