


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



CMPU-101: Problem-Solving and Abstraction Marc Smith Vassar College Spring 2007 2
George Boole (1815-1864)
Order of presentation: literals relational operators logical operators 3
true false System.out.println(true); boolean b = false; System.out.println(b); 4
< less than <= less than or equal == equal != not equal
= greater than or equal greater than
System.out.print("\nEnter int 1 : "); int i1 = kb.nextInt(); System.out.print("Enter int 2 : "); int i2 = kb.nextInt(); System.out.println("\ni1 == i2? " + (i1 == i2)); System.out.println("\ni1 < i2? " + (i1 < i2));
Suppose i 1 is 17 and i 2 is 99 : System.out.println("\ni1 == i2? " + i1 == i2); System.out.println("\ni1 == i2? 17" == i2); Error!
7
and && or || not! These are defined by truth tables. 8
false false false false true false true false false true true true x y x && y 9
false false false false true true true false true true true true x y x || y 10
false true true false x !x
arithmetic operators + , - , ***** , / , % relational operators <= , < , == , != , >= , > logical operators && , || ,!
public static boolean isPrime ( int n ) public static boolean isPalindrome ( String s )
Also known as lazy evaluation Java only evaluates what it has to evaluate. false && booleanExpression booleanExpression is not evaluated. true || booleanExpression booleanExpression is not evaluated.