×

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

How to Convert Decimal to Hexadecimal in Java

How to Convert Decimal to Hexadecimal in Java The hexadecimal number uses 16 values to represent a number. Numbers from 0 to 9 represented by digits and the numbers from 10...

3 minutes read.

Lombok Java

What is Lombok java? A well-liked and widely-used Java framework that is used to reduce or eliminate boilerplate code is called Project Lombok. Both time and effort are saved. We may...

7 minutes read.

Java String format() method

format() method returns a formatted String based on the given locale,specified format and arguments. Syntax: public static String format(String format , Object… args) Parameter: locale : It specifies locale value to be applied on...

2 minutes read.

Fibonacci Series Program in Java

Fibonacci Series Program in Java using Recursion Fibonacci series is a series whose every term is comprised of adding its previous two terms, barring the first two terms 0 and 1....

3 minutes read.

Prime Number Program in Java

Prime Number Program in Java using for loop A natural number which is greater than 1 and has only two factors the number itself and 1 is called prime number. In...

2 minutes read.

Factorial Program in Java using Recursion

Factorial Program in Java Factorials are used in mathematics to calculate permutations and combinations. It is denoted by the exclamatory symbol (!). Suppose, p is a number whose factorial is to...

3 minutes read.

Java Math sin() Method

The sin() method of Java Math class returns the trigonometric sine of the specified angle. Syntax: public static double sin(double a) Parameters: The parameter ‘a’ represents an angle measured in radians. Return Value: The sin() method...

1 minute read.

Palindrome number program in Java

Write java program to check if a number is palindrome in Java? A number that does not change on reversing is called a palindrome number. In other words, when reversing the...

3 minutes read.

Java Virtual Machine (JVM)

JVM is a virtual runtime environment to execute Java byte codes. The JVM doesn’t understand the keywords we used to write code. That is why it is converted into bytecode. It controls the...

3 minutes read.

Java Break Keyword

Break: The word Break is a keyword or a statement in a java programming language.This Keyword break is used to stop the execution of the loop or switch statements etc.The loop...

3 minutes read.

Java Math tanh() Method

The tanh() method of Java Math class returns the hyperbolic tangent of the specified double value. Syntax: public static double tanh(double x) Parameters: The parameter ‘x’ represents the number whose hyperbolic tangent is to...

2 minutes read.

Enterprise Java Beans

One of the many Java APIs for the common development of corporate software is Enterprise Java Beans (EJB). An EJB, a server-side software component, contains the business logic of an...

4 minutes read.

Java Short Keyword

Java supports eight different primitive datatypes. The language has predefined primitive datatypes that are given keyword names. Let's take a closer look at each of the eight primitive data types....

3 minutes read.

Convert Char array to string in java

A collection of characters is referred to as a string. A character array differs from a string in that the string is canceled by the special character "\0." A string...

4 minutes read.

How to write basic Java Programs

Java Basic Programs In this section, we will learn how to write basic Java programs. But first we need to take care of the following requirement list. To execute a Java program,...

4 minutes read.

Shopping Bill in Java

Java Shopping Bill Here in this program, we are about to create a JAVA class called Products which will have some properties or attributes like prod_name (Product Name ), qty (quantity),...

4 minutes read.

Java Map Example

In Java, the Map is an interface that is used mainly to denote key and value pairs. The central concept and theme of this mapping in the java collection framework...

4 minutes read.

Java Instanceof Keyword

To determine whether an object is an instance of the supplied type in Java, use the instanceof operator (class or subclass or interface). The type of comparison in java differentiates the...

4 minutes read.

Java Read File

Java provides its users with many ways of reading a file. To read a text file, you can use a FileReader, BufferedReader, or Scanner. Each utility offers something special for...

6 minutes read.

Java Type Casting

Type casting is a technique or process used in Java to convert one data type into another, either manually or automatically. The compiler performs the automatic conversion, and the programmer...

3 minutes read.