And, or, not
Conditions can be combined:
a && b(and) is true when bothaandbare true.a || b(or) is true when at least one of them is true.!a(not) is true whenais false.
A range check is the classic use of &&: a number is between 1 and 10 when it's at least 1 and at most 10.
int number = 7;
if (number >= 1 && number <= 10) {
System.out.println("In range");
}
if (number < 1 || number > 10) {
System.out.println("Out of range");
}
System.out.println(!(number > 5));
In range
falseJava checks && and || from left to right and stops as soon as the answer is known: in a && b, when a is false, b isn't looked at.