lecture6 - Administrative Issues Program Statements Part 2...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Program Statements Part 2 Lecture 6 Administrative Issues • Due Today – Program 1 • Assigned Today – Program 2 • Due next Wednesday – Homework 1 • Due next Friday Boolean Expressions • What are boolean expressions ? – Expressions that evaluate to true or false • Used as if statement condition • Many more uses in future lectures • Deserve more in-depth coverage Equality/Relational Operators • Presented in previous lecture • Evaluate to boolean value • Example: (age < 18) (milage == 3000) Greater than or equal to >= Greater than > Less than or equal to <= Less than < Not equal to != Equal to == Meaning Operator Logical Operators • Take boolean operands • Produce boolean results Logical OR || Logical AND Logical NOT ! Meaning Operator Either a or b are true a || b Both a and b are true a is false !a True If… Operator Not Truth Table false true true false !a a Unary Operator: Just one argument.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
And Truth Table true true true false false true false true false false false false b a Binary Operator: Two arguments. Or Truth Table true true true true false true true true false false false false a||b b a Binary Operator: Two arguments. Logic Test = false || true = (!false) || false = !(false || false) Logical Operator Examples if (done || (time > MAX_TIME)) System.out.println(“Finished.”); if (netWorth > 1000000)) System.out.println(“Innocent.”); if System.out.println(“NOT POSSIBLE!”); ‘Short Circuited’ Operators • Both and || are can be short-circuited • Left-side expression evaluated first • If sufficient to decide the entire operation, the right side is never evaluated! • Can be useful: if System.out.println(“You got an A!”); CAUTION • Be careful with shortcuts like short- circuiting • Code can be hard to read Your code must be easy to read by humans • Other languages might not short-circuit
Background image of page 2
Comparing Characters • Characters are compared via the numeric code assigned to each character • Java uses the Unicode standard • Codes in Appendix C (pg 690) –‘ A ’-‘ Z ’ corresponds to 65-90 –‘ a ’-‘ z ’ corresponds to 97-122 –‘ 0 ’-‘ 9 ’ corresponds to 49-57 • Caps less than lower case! Digits lowest! 2 Minute Exercise
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

lecture6 - Administrative Issues Program Statements Part 2...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online