Tuesday, 14 April 2015

How To Implement Logical Operations In Java

This tutorial shows how to implement logic gates in java in easiest way in this tutorial we have performed AND,OR and NOT gate functions.This method can be useful in many situations for performing logical operators.

CODING:

class logicaloperators
{
public static void main(String args[])
{
//equivalent to 0101 in binary
int a=5;
//equivalent to 1000 in binary
int b=8;
//performing OR operation
int c= a|b;
//performing AND operation
int d=a&b;
//performing NOT operation
int f=~a;
System.out.println("a|b = "+c);
System.out.println("a&b = "+d);
System.out.println("~a = "+f);
}
}

OUTPUT:



No comments:

Post a Comment