Logical Operations in Java

There are logical operations in Java &&, ||,>, <, ==,> =, <=,!,! =. Logical operations in Java and their meanings.

 

Logical Processor Meaning
&& and
|| or
> it is greater
< it is less
== equals
>= greater than or equal to
<= less than or equal to
! it is not
!= not equal

 

import java.io.*;

public class Main
{
	public static void main(String[] args) {
	    boolean b1,b2;
	    b1=true;
	    b2=false;
	    System.out.println("b1:"+b1+" b2:"+b2);
	    System.out.println("b1 && b2 "+(b1&&b2));
	    System.out.println("b1 || b2 "+(b1||b2));
	    int number1,number2;
	    number1=1;
	    number2=2;
	    System.out.println("number1 :"+number1);
	    System.out.println("number2 :"+number2);
	    b1=(number1>number2);
	    System.out.println(number1 +">"+number2+" "+b1);
	    b1=(number1<number2);
	    System.out.println(number1 +"<"+number2+" "+b1);
        b1=(number1==number2);
	    System.out.println(number1 +"=="+number2+" "+b1);
        b1=(number1>=number2);
	    System.out.println(number1 +">="+number2+" "+b1);
	    b1=(number1<=number2);
	    System.out.println(number1 +"<="+number2+" "+b1);
	    b1=(number1!=number2);
	    System.out.println(number1 +"!="+number2+" "+b1);
	    System.exit(0);
	}
}

output:

b1:true b2:false
b1 && b2 false
b1 || b2 true
number1 :1
number2 :2
1>2 false
1<2 true
1==2 false
1>=2 false
1<=2 true
1!=2 true

 

Tagged In:

Software developer

26 Total Posts