Home Java Beginners Java - Boolean Expression and Operation in Java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java - Boolean Expression and Operation in Java

Advertisement
In this example you will see that how the expression returns a boolean value which is either true or false.

Java - Boolean Expression and Operation in Java

     

Boolean expression performs the relational or logical operations and returns the boolean value (True/False).

In this example you will see that how the expression returns a boolean value which is either true or false. This example illustrates you how to make a boolean expression by using relational operators and how to use the returned value of the expression.

This program reads two int type value and print the message with the returned boolean value for the boolean expression in which many types of relational operators are used.

Code of the program : 

import java.io.*;

public class booleanOperation{
  public static void main(String[] args) throws Exception{
 
 try{
  int a;
  
  int b;
  BufferedReader in = new BufferedReader
(
new InputStreamReader(System.in));
  a = Integer.parseInt(in.readLine());
  b = Integer.parseInt(in.readLine());
  System.out.println("a = " + a + "and\nb = " + b);
  System.out.println
(a +
 " is greater than " + b + " : " + (a > b));
  System.out.println
(a + 
" is less than " + b + " : " + (a < b));
  System.out.println
(a + 
" is equal to " + b + " : " + (a == b));
  System.out.println(a + " is greater or 
equal to " 
+ b + " : " + (a >= b));
  System.out.println(a + " is less than or 
equal to " 
+ b + " : " + (a <= b));
  System.out.println
(a +
 " is not equal to " + b + " : " + (a != b));
  System.out.println
(a +
 " is equal to " + b + " : " + (a == b));
  }
 
 catch(IOException e){
  System.out.println(e.getMessage());
  System.exit(
0);
  }
  }
}

Download Boolean Expression and Operation Example

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 4, 2007

Ask Questions?    Discuss: Java - Boolean Expression and Operation in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com