In this java examples of Java tutorial, we will study about one of the Java logical operator which is Java OR operator with example. We will see Java OR operator example and why we need to of OR operator in Java.
Java OR Operator
Java OR operator is Java logical operator. OR operator returns true if any of the statement is true while doing comparison.
Syntax of Java OR operator
OR operator in Java is written as
||
Java OR operator Example
Lets understand the functionality of Java OR operator by taking an example.
public class JavaExamples { public static void main(String[] args) { //Java logical OR operator Example in Java int a = 10; int b = 20; int c = 30; System.out.println((a < b) || (c > b)); System.out.println((a > b) || (c > b)); } }
Output
true true
Explanation
Let’s understand by taking same example we take in Java AND operator example.
Here we have two statements:
In first statement we have condition where a is less than b which is true and another condition is c is greater than b which is also true, so true OR true = true.
In second statement we have condition where a is greater than b which is false and another condition is c is greater than b which is true, so false OR true = true.
So, In this post of Java logical operators, we study and understand about Java OR operator by taking an example.