×

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 vs Dot Net

Java : Java is a pure object oriented language. It was introduced by James Gosling in the year 1995. The first public implementation of java was done by sun micro systems...

3 minutes read.

Java Set Interface

We use set when we don't want to allow duplicate entries. All Set implementations do not allow duplicates. HashSet: This class stores its elements in hash tables. It uses the hashCode()...

3 minutes read.

Hierarchy of operators in Java

Operators are the most frequently used terminology in any area of programming, and it helps in various approaches to efficiently solve daily life problems by computer programming. The simple addition of...

4 minutes read.

Java Math sqrt() Method

The sqrt() method of Java Math class returns the accurately rounded positive square root of the specified double value. Syntax: public static double sqrt(double a) Parameters: The parameter ‘a’ represents the number whose square...

2 minutes read.

Display List of TimeZone with GMT and UTC in Java

It is vital to establish the right TimeZone in Java code when working with dates for Daylight Saving Time. In this part, we will present the time zones with GMT. TimeZone Those...

5 minutes read.

Arithmetic Operations on String in Java

Introduction Arithmetic, Relational, Bitwise, and Logical operators are all available in Java. Simple mathematical calculations are performed using Java arithmetic operators. Basic Arithmetic operators are considered in Java to be Addition,...

4 minutes read.

String Handling Method in Java

What is a String? Strings are a bundle of different characters that are normally used in Java programming language. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.

Java Binary Tree

The non-linear data structure known as a binary tree is a type of tree, and because it stores data in a hierarchical manner, it is mostly utilised for finding and...

7 minutes read.

Producer Consumer Problem in Java Using Synchronized Block

The producer-consumer dilemma is a well-known instance of a multi-process synchronization issue in computing. Two processes—the producer and the consumer—are described in the issue, and they share a single, fixed-size...

4 minutes read.

Java Integer reverseByte() method

The reverseByte() method of Java Integer class returns the value obtained by reversing the order of the bytes in the 2’s complement binary representation. Syntax public static int reverseByte (int i) Parameters The parameter...

1 minute read.

Split String into String Array in Java

The String split() technique returns a variety of divided strings after the strategy parts the given String around matches of a given normal articulation containing the delimiters. The ordinary articulation...

4 minutes read.

Java Math signum() Method

The signum() method of Java Math class returns the signum function of the value. Syntax: public static double signum(double d)public static float signum (float d) Parameters: The parameter ‘d’ represents the floating-point value whose...

2 minutes read.

Java Wrapper classes

Java Wrapper classes A wrapper class is a class whose object contains a primitive data type; moreover it provides a way to use primitive data type (int, boolean, etc.) as objects. Wrapper...

2 minutes read.

Tribonacci series in Java

The Fibonacci series and the Tribonacci sequence are linked. The Fibonacci sequence, each element summates the three preceding terms, is expanded into the Tribonacci series in Java. Through specific examples,...

3 minutes read.

String vs StringBuilder

String vs StringBuilder In this section, we will discuss the comparison between Java String and StringBuilder class. String In Java, a string is treated as an object that represents a sequence of characters....

4 minutes read.

How to override toString() method in Java?

Java is an object-oriented language. It only works with classes and objects. Thus, whenever we need to calculate, we need an object or objects that belong to the class. The Java method...

2 minutes read.

How to Convert String to char in Java

How to Convert String to char in Java There are two methods to convert String to char are: Using charAt() method Using tocharArray() method Using charAt() method This is the method of String class that...

3 minutes read.

Knapsack problem in Java

We have a collection of items in the knapsack problem. Every object has a weight and a value. These things should go in a knapsack. But there is a weight...

3 minutes read.

String Palindrome Program in Java

String Palindrome Program in Java The palindrome is a string, phrase, word, number, or other sequences of characters that can be read in both directions i.e. forward (left to right) and...

11 minutes read.

Ganesha’s Pattern in Java

This part teaches us how to use stars and other special characters to write Ganesha's Pattern in Java programming. Among the most challenging Java pattern applications to code. The Ganesha will be...

3 minutes read.