Lazy evaluation of boolean predicates - Java Language Basics

Java examples for Language Basics:boolean

Description

Lazy evaluation of boolean predicates

Demo Code

public class Main {
  public static void main(String[] args) {
    double x = 3.14, y = 0.0;
    boolean test1, test2;

    test1 = (y != 0.0);//from   w w w .j  a v  a 2s .c om
    test2 = (x / y > 2.0);

    System.out.println("Test1:" + test1 + " Test2:" + test2);
    System.out.println("We did not evaluate x/y that isequal to " + (x / y));

    if ((y == 0.0) || (x / y > 2.0)) { // Block
      System.out.println((x / y));
    }
  }
}

Result


Related Tutorials