


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to boolean logic and operators in java for students enrolled in the cmpu-101 course at vassar college during spring 2007. It covers boolean literals, relational operators, logical operators, and their precedence, as well as short-circuiting. Students will learn how to use these operators in java code and understand their importance in problem-solving and abstraction.
Typology: Study notes
1 / 4
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.