×

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

Console Errors in Java

An unlawful motion taken through the person that reasons this system to act abnormally is amistake until this system is compiled or run; maximum programming mistakes pass unnoticed.The software is...

3 minutes read.

Java String equals() method

equals() method compares two string based on the their content. Syntax public boolean equals(Objects anObject) parameter anObject: Object to be compared with the current String. Returns It returns true when the current String is equivalent to...

1 minute read.

POJO in Java

Plain old Java Object, in short, is called POJO in Java. POJO is an everyday object that is not subject to any specific limitations. We can use POJO in any Java...

3 minutes read.

Brilliant Number in Java

It is a number N that is made up of two prime numbers that have the same number of digits and is called a brilliant number. Several/Some of the brilliant Numbers...

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

Matrix Multiplication Program in Java

Matrix Multiplication Program in Java The matrix multiplication program in Java is the continuation of the matrix program in Java that we have already discussed earlier. In this section, we will...

3 minutes read.

Calculator Program in Java

Calculator Program in Java A calculator performs the basic mathematical operations such as addition, subtraction, multiplication, etc. In this section, we will create a calculator program in Java using switch case...

5 minutes read.

Generics in Java

Generics in Java Parameterizedtypes mean generic. Generics allow types (Character, Integer, String, …, etc., as well as user-defined types) to act as parameters to interfaces, classes, and methods. Generics in Java...

9 minutes read.

Use Of Adapter class in Java

An adapter class in Java enables listener interfaces to be implemented by default. The Delegation Event Model is where the idea of listener interfaces first appeared. It is one of...

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.

Object class in Java

In Java, a class is a file containing the Java byte code. It can essentially specifically be executed on the JVM (Java Virtual Machine), fairly significant. The JVM mostly generally...

6 minutes read.

How to get Day Name from Date in Java

We'll write a Java application to extract the day's name from the Date in this section. When dealing with Date and time in Java, the following classes are used. Class for Calendars:...

6 minutes read.

Java SE vs EE

Java : Java is an independent platform. It works on any kind of operating system. We use java to develop and to focus on large or major projects. The goal of...

3 minutes read.

Difference between JIT and JVM in Java

In this tutorial, we will discuss the difference between JIT (Just In Time Compiler) and JVM (Java Virtual Machine) in Java. Before we move to the differences, let's understand what...

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

Java Integer reverse() method

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

1 minute read.

Java RMI

What is RMI in Java? A framework for developing distributed Java applications is provided by the RMI (Remote Method Invocation) API. An object can call methods on an object running in...

4 minutes read.

Java array list remove time complexity

Java: We know that java is one of the programming languages. The main feature of java which is not in C or object oriented programming language is platform independence. Not only the...

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.

Race Condition in Java

Java is a multi-threaded programming language, race conditions are more likely to arise. Mostly because data can change when multiple threads visit the same resource simultaneously. Race conditions are concurrency...

3 minutes read.