

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
Material Type: Exam; Class: Transition to Object-Oriented Programming; Subject: Computer Science; University: Cornell University; Term: Unknown 2008;
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


In some programming languages, for example Matlab and C, integers are used to represent the logical values true and false. Generally, 0 is used for false , and any other integer can be used for true. Java handles boolean values differently. There is a (primitive) type boolean , whose values are true and false (that's it). This type has five operations whose operands are booleans: Type boolean Values: true , false Operations:! ( not ), && ( and , or conjunction ), || ( or , or disjunction ) == (equality, or equivalence), != (inequality, or inequivalence) Here is a table that defines the five operations. b c | !b b && c b || c b == c b != c false false | true false false true false false true | true false true false true true false | false false true false true true true | false true true true false We evaluate a few expressions in the interactions pane and discuss the operations.
b? c : false // equivalent to b && c You will see this conditional expression later. Get used to it; it is useful. In the same way, true || c is true no matter what the value of c is, so c is not evaluated in this case. The expression b || c is equivalent to if b then true else c, or the Java expression b? true : c As you will see in several assignments, short-circuit evaluation is a useful tool in writing boolean expressions. 2