×

Java Boolean logicalAnd() Method

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

Syntax:
public static boolean logicalAnd (boolean a, boolean b)

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

Return Value:
The logicalAnd () method returns the result after implementing logical AND operation on the parameters a and b.
? It returns true, if and only if both the parameters are true.
? It returns false, if either of the parameter is false.

Example 1

public class JavaBooleanLogicalAndMethodExample1 {
    public static void main(String[] args) {
        Boolean b1 = true;
        Boolean b2 = false;
    // return boolean value after implementing logical And operator
        Boolean b3 = Boolean.logicalAnd(b1,b2);
        Boolean b4 = Boolean.logicalAnd(b1,b1);
        Boolean b5 = Boolean.logicalAnd(b2,b2);
        Boolean b6 = Boolean.logicalAnd(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 = false
2. true true = true
3. false false = false
4. false true = false

Example 2

public class JavaBooleanLogicalAndMethodExample2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter your Age.");
        Double d1 = scanner.nextDouble();
        Boolean b1 = true;
        Boolean b2 ;
        if (d1 >=18) {
            b2 = true;
            // logicalAnd() method will return true
            Boolean b3 = Boolean.logicalAnd(b1,b2);
            if((b3==true)) {
                System.out.println("You are eligible to vote");
            }
        }
        else{
            System.out.println("Sorry! You are not eligible for voting.");
        }
    }
}

Output

Enter your Age.
18
You are eligible to vote

Example 3

import java.util.Scanner;
public class JavaBooleanLogicalAndMethodExample3 {
    static int j=1;
    public static void main(String[] args) {
          Scanner scanner = new Scanner(System.in);
          Boolean b1 = true;
          Boolean b2 = true;
          System.out.println("Enter a number.");
          int a=scanner.nextInt();
          if (a>15|| a<=0){
              b1=false;
          }
          Boolean b3=Boolean.logicalAnd(b1,b2);
          if (b3) {
              for (int i = 1; i <= 150; i++) {
                  int mul=a*10;
                  if (i%a == 0) {
                      System.out.println(a+" * "+ j++ +" = "+i);
                  }
                  if (i==mul){
                      break;
                  }
              }
          }
          else{
              System.out.println("Sorry ! Number is out of range. Plz try a number btw 1-15 ");
          }
    }
}

Output:

Enter a number.
9
9 * 1 = 9
9 * 2 = 18
9 * 3 = 27
9 * 4 = 36
9 * 5 = 45
9 * 6 = 54
9 * 7 = 63
9 * 8 = 72
9 * 9 = 81
9 * 10 = 90

Related Topics

Set Matrix Zeros in Java

In coding round interviews, it is frequently asked as the most significant challenge. an m*n matrix is provided. Set the entire column and row of the matrix to 0 if any...

6 minutes read.

Ramanujan Number or Taxicab Number in Java

In this section, we will discuss what a Ramanujan number (also known as a Hardy-Ramanujan number) is and how to use a Java programme to determine if a given integer...

3 minutes read.

Java Integer parseUnsignedInt() method

The parseUnsignedInt() method of Java Integer class parses the string argument as an unsigned decimal integer. The second parameter parses the string argument as an unsigned integer in the radix specified...

2 minutes read.

Java Boolean logicalAnd() Method

The logicalAnd() method of Java Boolean class returns the result of implementing logicalAND operation on the specified Boolean operands. Syntax:public static boolean logicalAnd (boolean a, boolean b) Parameters:The parameters ‘a’ and ‘b’...

2 minutes read.

ArrayDeque in Java

ArrayDeque The ArrayDeque is one of the essential concepts in java to implement the deque interface. It will allow us to apply a resizable array to implement the Deque interface. This...

8 minutes read.

How to check the Java version in cmd

To make programs that can run on our systems, we need to install programming language-related software in our systems. Different programming languages require different types of software, aka IDEs (Integrated...

5 minutes read.

Merge Sort in Java

Merge Sort in Java Merge sort in Java uses the divide and conquer approach to sort the given array/ list. There are three steps involved in the merge sort. 1) Divide the...

5 minutes read.

Time Class Operation in Java

The Java SQL package includes the time class. This class is merely a lightweight wrapper for java. util. THANKS TO THE recognize BC API can recognize this as a SQL...

3 minutes read.

Level order Traversal of a Binary Tree in Java

In Java, a level order traversal of a tree structure is also referred to as the breadth-first traversal of the binary tree. Regarding the subsequent binary tree: Level order traversal is as...

5 minutes read.

Character Array in Java

A character array is an array which holds values of character data types. It is different from a string array. The character array, string, and StringBuffer classes in the Java...

4 minutes read.

Java Integer toUnsignedLong() method

The toUnsignedLong() method of Java Integer class returns a long value by simply converting the given argument to long after an unsigned conversion. Syntax public static long toUnsignedLong (int  x) Parameters The parameter ‘x’...

1 minute read.

How to Install Java on MAC

There are many possible ways to install java on mac. This article is based on the installation of java on mac. The operating system platform is Mac OS X, macOS and...

3 minutes read.

Example of Static import in Java

Static keyword Java's static keyword is mainly used to control memory. Variables, methods, blocks, and nested classes are compatible with the static keyword. Instead of an instance, the static keyword is...

3 minutes read.

If Condition in Lambda Expression Java

The new and significant lambda expression feature of Java was added in Java SE 8. It provides a clear and concise mechanism for describing a single-method interface using an expression....

4 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.

Determine the Upper Bound of a Two-Dimensional Array in Java

Multi-Dimensional Array Multi-faceted exhibits in Java are regular and can be named various clusters. Information in a two-layered bunch in Java is put away in 2D even structure. A two-layered collection...

3 minutes read.

Java Interface Keyword

An interface is also known as the blueprint in Java. It has constants of static values and methods of abstraction. The interface is a mechanism used by Java to declare...

3 minutes read.

How to Iterate a HashMap in Java?

Hash-map is a class of Java collections framework which has the functionality to implement the Map interface of Java. It stores the data in key-value pairs and can be accessed...

5 minutes read.

Binary Strings Without Consecutive Ones in Java

N, an integer, is provided. Our objective is to determine the overall number of strings with length N that do not include successive 1s. Example: Input: 3 Output: 6 Explanation The binary forms of length...

6 minutes read.

Model Class in Java

In this section, we will be acknowledged about the model class in Java, its purpose and its uses. Also, we will learn how is this created and leveraged in java. Model...

4 minutes read.