{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture6 - Administrative Issues Program Statements Part 2...

Info icon This 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 && b a is false !a True If… Operator Not Truth Table false true true false !a a Unary Operator: Just one argument.
Image of page 1

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

View Full Document Right Arrow Icon
And Truth Table true true true false false true false true false false false false a&&b 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 = true && false = false || true = !(false && true) = (!false) || false = !(false || false) = true && (!false) = false || (true && (!true)) Logical Operator Examples if (done || (time > MAX_TIME)) System.out.println(“Finished.”); if (status.equals(“Famous”) && (netWorth > 1000000)) System.out.println(“Innocent.”); if (!(a||b) && (a&&b)) 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 ((tests != 0) && ((testPoints/tests) > 90)) 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
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 True or False (‘a’ > ‘A’) (‘z’ < ‘A’) (‘Y’ < ‘K’) (‘8’ < ‘0’) (‘c’ == ‘C’) (‘c’ > ‘g’) (‘9’ < ‘f’) Comparing Strings Strings are sorted based on the Unicode digits for each letter
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern