Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment
Back to Classroom
Conditional OR
Introduction To Java Course
Engineers From These Top Companies and Universities Trust EXLskills
1M+ Professionals | 100+ Institutions
This is the EXLskills free and open-source Introduction To Java Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.
Is this course FREE?
Yes, this a 100% free course that you can contribute to on GitHub here!
Contrary to the "AND" operator, the "OR" operator is used in a boolean expression to check if at least one of expressions are true.The "OR" operator is also a logical operator because it combines two true/false values into a single true/false value. Let's take a look at the functionality of the "OR" operator.
ConditionalOrExample.java
package exlcode;
public class ConditionalOrExample {
public static boolean exampleVariableOne = true;
public static boolean exampleVariableTwo = true;
public static boolean exampleVariableThree = false;
public static boolean exampleVariableFour = false;
public static void main(String[] args) {
// returns true if either one of the boolean values are true
if (exampleVariableOne || exampleVariableTwo) {
System.out.println("The boolean expression is true");
} else {
System.out.println("The boolean expression is false");
}
if (exampleVariableOne || exampleVariableThree) {
System.out.println("The boolean expression is true");
} else {
System.out.println("The boolean expression is false");
}
if (exampleVariableThree || exampleVariableFour) {
System.out.println("The boolean expression is true");
} else {
System.out.println("The boolean expression is false");
}
}
}
The "OR" operator only checks to see if one the boolean values are true. Here are the possibilities and the results for each case.
true || true = true
true || false = true
false || true = true
false || false = false
The "OR" operator functions similarly to how the word "or" is used in English. If one of the options you mention when using "or" is met, the other one doesn't matter. For example, if you are looking for a muffin or a donut, your needs are satisfied when you find a muffin, a donut, or both.