04-conditionals

04-conditionals - Conditionals and Decision Statements CSE...

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

View Full Document Right Arrow Icon
Conditionals and Decision Statements CSE 114: Computer Science I SUNY at Stony Brook 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Making Decisions Many programs must behave differently when presented with different situations e.g., choosing an action from a menu, determining what sales tax rate to charge, etc. Java offers two similar ways to handle these situations: branching (if-else) statements selection (switch) statements 2
Background image of page 2
True and False Values A boolean expression is one whose value is either true or false (but not both!) Ex. a > b or var1 == var2 Boolean (logical) equality operator: == Common programming error: using ‘=’ (assignment) instead of “==” (equality) Ex. if (x = 5) 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Boolean Operations Decisions are made in Java programs using boolean logic (i.e., values of true and false) and operations Relational operators are used to compare two values Logical operators combine smaller boolean expressions into a single, larger expression 4
Background image of page 4
Operator Meaning Example < Less than age < 30 > Greater than height > 6.2
Background image of page 5

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

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

This note was uploaded on 04/03/2009 for the course CSE 114 taught by Professor Tashbook during the Spring '08 term at SUNY Stony Brook.

Page1 / 21

04-conditionals - Conditionals and Decision Statements CSE...

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

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