×

Java Boolean logicalOr() Method

The logicalOr() method of Java Boolean class returns the result of implementing logical OR operation on the specified Boolean operands.

Syntax:

public static boolean logicalOr (boolean a, boolean b)

Parameters:

The parameters ‘a’ and ‘b’ represents first and second operands.

Return Value:

The logicalOr () method returns the result after implementing logical OR operation on the parameters a and b.

  • It returns true, if either of the parameter is true.
  • It returns false, if and only if both the parameters are false.

Example 1

public class JavaBooleanLogicalOrMethodExample1 {
    public static void main(String[] args) {
        Boolean b1 = true;
        Boolean b2 = false;
        // return boolean value after implementing logical OR operator
        Boolean b3 = Boolean.logicalOr(b1,b2);
        Boolean b4 = Boolean.logicalOr(b1,b1);
        Boolean b5 = Boolean.logicalOr(b2,b2);
        Boolean b6 = Boolean.logicalOr(b2,b1);
        System.out.println("1. "+b1+"  "+b2+" = "+b3);
        System.out.println("2. "+b1+"  "+b1+" = "+b4);
        System.out.println("3. "+b2+"  "+b2+" = "+b5);
        System.out.println("4. "+b2+"  "+b1+" = "+b6);
    }
}

Output

1.true false = true
2.true true = true
3.false false = false
4.false true = true

Example 2

import java.util.Scanner;
public class JavaBooleanLogicalOrMethodExample2 {
    public static void main(String[] args) {
        Boolean bool1 = true;
        Boolean bool2 = false;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the dividend : ");
        int dividend =scanner.nextInt();
        System.out.print("Enter the divisor : ");
        int divisor =scanner.nextInt();
        if(dividend<0 ||divisor<=0||divisor> dividend){
            bool1 = false;
        }
        Boolean bool3 =Boolean.logicalOr(bool1,bool2);
        if(bool3==true) {
            System.out.println("Quotient = "+dividend/divisor +"\nRemainder = "+dividend%divisor);
        }
        else{
            System.out.println("Plz enter a valid dividend and divisor.");
        }
    }
}

Output

Enter the dividend : 67
Enter the divisor : 0
Plz enter a valid dividend and divisor.

Example 3

import java.util.Scanner;
public class JavaBooleanLogicalOrMethodExample3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a, b;
        Boolean b1 = false;
        Boolean b2 = false;
        System.out.println("Enter two no.s");
        a = scanner.nextInt();
        b = scanner.nextInt();
        if (b>a){
            b1=true;
        }
        if (a == b) {
            System.out.println("Both are equal.");
        }
         else {
            boolean b3 = Boolean.logicalOr(b1, b2);
            if (b3 == true) {
                System.out.println(b + " is greater");
            }
            else {
                System.out.println(a + " is greater");
            }
         }
    }
}

Output

Enter two no.s
56
109
109 is greater

Related Topics

Java Strings

String class is the most used class in Java programming language. The string is the sequence of characters, which is treated as objects in Java. Creating String objects We create String objects...

5 minutes read.

Java Queue

The Java.util package has the interface Queue, which does extend the Collection interface. It is used to protect the parts that are managed using the FIFO approach. Being an interface, the...

5 minutes read.

Radix Sort in Java

Radix Sort in Java Radix sort in Java uses the digits of the numbers given in the sorted array to sort the numbers. The radix sort uses the place value of...

5 minutes read.

Java String hashCode() method

Java String hashCode() method returns hash code for current String. hash code for string object is computed as s[0]*31^(n - 1) + s[1]*31^(n - 2) + ... + s[n - 1] Using int...

2 minutes read.

Java Primitive Data Types

Primitive data types are the simplest data types in a programming language. They’re predefined in the language. The names of the primitive types are quite descriptive of the values that...

2 minutes read.

Java Integer numberOfLeadingZeros() method

The numberOfLeadingZeros()  method of Java Integer class returns the total number of zero bits preceding the highest-order one-bit in the 2’s complement binary representation of the specified int value.  Syntax public static...

1 minute read.

Rotate matrix by 90 degrees in Java | Rotate matrix in Java clockwise and anti-clockwise

In this article, you will be acknowledged about what is a matrix along with an example. Most importantly you will be equipped knowledge on how to rotate the matrix by...

4 minutes read.

CopyOnWriteArrayList in Java

The CopyOnWriteArrayList is used to implement the List Interface. It is the improved version of ArrayList. The operations like add, remove, set, update etc, these operations are done by creating...

5 minutes read.

Java InetAddress class

InetAddress class The InetAddress class refers to the IP address, both IPv4 and IPv6.An instance of an InetAddress consists of an IP address and possibly its corresponding hostname. It provides a method to get the...

9 minutes read.

Java Integer lowestOneBit()

The lowestOneBit () method of Java Integer class returns an int value with at most a single one-bit, in the position of the lowest-order one-bit in the specified int value.  Syntax public...

2 minutes read.

Java Protected Keyword

An access modifier is a keyword that Java protects. It can be used to constructors, methods, inner classes, and variables. Variables, methods, and constructors that have been marked protected in...

3 minutes read.

Java Integer compareUnsigned() method

The compareUnsigned() method of Integer class compares two int objects numerically by treating the values as unsigned. Syntax public static int compareUnsigned(int x , int y) Parameters The parameters ‘x’ and ‘y’ represent the...

1 minute read.

Advantages and Disadvantages of Strings in Java

What is a String? Java is an object-oriented, platform-independent, high-level, general-purpose, and interpreted programming language.Sun Microsystems is known as the founder of java in 1991; the Java programming language was developed...

4 minutes read.

Reverse a String in Java

Reversing a string means that if we have a string called “what is your name”, the reversed format is “eman ruoy si tahw”. Reversing a string involves totally flipping the...

3 minutes read.

Java Extends vs Implements

Java: We known that the java is a pure object oriented programming language. Java programming language consists of many features such as portable, plat form independence, secured, robust, simple, architecture neutral,...

4 minutes read.

Chromatic Number in Java

The chromatic number is the bare minimum of colours necessary to accurately colour any graph. To put it another way, the chromatic number can be thought of as the bare...

6 minutes read.

Java RandomAccessfile

Writing and reading to random access files are done using this class. An array of many bytes is how a random access file operates. By changing the implied file pointer...

3 minutes read.

Java Generate UUID

What java Generate UUID? A 128-bit long value that is universally unique serves as the basis for the terms UUID (Universally Unique Identifier) and GUID (Globally Unique Identifier). Hexadecimal (octet) digits...

5 minutes read.

Difference Between Thread.start() and Thread.run()

In the Java programming language, the multi-threading concept consists of the start() and run() methods. Thread.start(): The thread's execution is initiated by invoking the start() method. The start() method operates two threads...

4 minutes read.

Java Final Keyword

In Java, the last keyword is used to limit the user. The applications of the java final keyword have large range of usage in program development. Last can be: variablemethodclass A final...

3 minutes read.