×

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 Worker Class

What is a Worker? A service which executes Work - flow and Activities is referred to as a Worker. On user-controlled hosts, workers are defined and put into action. The Worker...

3 minutes read.

Process and Thread in Java

Process It is a program that is running on your computer. The process is a heavy-weight, which takes memory separately to other processes. The process may be a small background task like spell-checker; it...

11 minutes read.

Java Editors

A straightforward text editor may be used to create Java applications. However, a Java integrated programming environment (IDE) enables the software developer to create programs more quickly. An IDE offers...

4 minutes read.

Zigzag Array in Java

In this tutorial, we discuss, what is zigzag array and its example. Even we will create the java program. In this program, we convert the simple array into a zigzag...

4 minutes read.

Java Private keyword

A Java access modifier is a private keyword. It can be used to inner classes, methods, and variables. It is the type of access modifier that is most constrained. Privately declared...

4 minutes read.

Java File Input Stream

Java makes use of stream ideas to speed up input and output processes. All packages of input and output streams are contained in java.io.package. Stream: A stream is nothing more...

5 minutes read.

Java Import Keyword

Java's import keyword used in the code that follows the import statement, a Java class is declared. Once a Java class is declared, it is possible to use the class...

6 minutes read.

Generic queue in Java

Before understanding how to implement a generic queue in java, one must know about generics and queue in java. Generics in Java Generics are parameterized types. The goal is to enable type...

6 minutes read.

Convert list to array Java

One of the popular collection interfaces for storing an ordered collection is the List. The List interface may contain repeating groups and preserves the insertion order of entries. This article will...

4 minutes read.

How to reverse a linked list in java

The process of reversing a linked list in Java will be covered in this section. One of the most common questions in interviews is about reversing a linked list. If...

11 minutes read.

File Operation in Java

In Java, a file is an Abstract data type. These are used to store the data which is related. Files are named storage locations. With a file we can perform...

7 minutes read.

Stack vs Heap in Java

In Java, whenever we declare an object or create a variable, whether it is an instance variable, local variable, or static variable, a certain memory is used to store the...

4 minutes read.

String Pool in Java

String Pool in Java: String is one of the most important discussed topics in Java. There are a lot of concepts related to the String and one of them is...

5 minutes read.

Functional Interfaces in Java

Java has forever remained an Object-Oriented Programming language. By object-oriented programming language, we can declare that everything present in the Java programming language rotates throughout the Objects, except for some...

11 minutes read.

Java Thread class

Thread class The thread represents a part of the process. Every process can have multiple associated threads in which every thread may execute the same or different job. By default, each thread assigns...

16 minutes read.

Finding Odd Occurrence of a Number in Java

In this tutorial, we will learn how to find the odd occurrence of a number through a java program. Let us consider an array of non-negative integers. Here, except for one...

6 minutes read.

SHA Decrypt in Java

In this section, we will be acknowledged about the decryption of SHA in Java. Java SHA The SHA cryptographic hash algorithm in cryptography outputs the hash value as an approximately 40-digit-long hexadecimal...

4 minutes read.

Salesman Problem in Java

The Traveling Salesman Problem determines the shortest path that visits each city approximately once and loops back to the starting location. Another Java problem that is most like the Traveling...

5 minutes read.

How to check if date is valid in Java?

In this article, you will acknowledge about how to verify if a date is valid or not. For this you will learn the approach, you will be able to write...

3 minutes read.

Java Xmx

This section will explain what Xmx in Java is and how to establish a Java application's maximum heap size. When we execute a Java application, it occasionally displays an error message...

3 minutes read.