Fall 2012, The College of Saint Rose

BooleanDemo BlueJ Project

BooleanDemo Source Code

The Java source code for BooleanDemo is below. Click on a file name to download it.

### BooleanDemo.java

```/*
* Example BooleanDemo: demonstrate a variety of constructs related
* to boolean (true/false) data
*
* Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012
*
* \$Id: BooleanDemo.java 1917 2012-09-27 02:36:22Z terescoj \$
*/

import java.util.Scanner;

public class BooleanDemo {

public static void main(String[] args) {

// construct a Scanner for keyboard input
Scanner input = new Scanner(System.in);

// read in 3 numbers that will be used in subsequent comparisons
System.out.print("Enter 3 integer values: ");
int x = input.nextInt();
int y = input.nextInt();
int z = input.nextInt();

System.out.println("Using x=" + x + ", y=" + y + ", z=" + z);

// demonstrate the basic arithmetic comparisons, note that we can
// print out the result of comparison operator
System.out.println("x == y is " + (x==y));  // is x equal to y?
System.out.println("x != y is " + (x!=y));  // not equal
System.out.println("x < y is " + (x y is " + (x>y));
System.out.println("x <= y is " + (x<=y));
System.out.println("x >= y is " + (x>=y));

// boolean logical operators
System.out.println("!(x < y) is " + !
(x

```