{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture7-chapter3

# lecture7-chapter3 - Lecture 7 Chapter 3 Review CS 170...

This preview shows pages 1–18. Sign up to view the full content.

Lecture 7: Chapter 3 Review CS 170, Section 000, Fall 2009 17 September 2009

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

View Full Document
Lecture Plan Logistics (important announcements) Chapter 2 “quiz” HW1 Questions? Chapter 3 review 9/21/2009 CS170, Section 000, Fall 2009 2
2.13: Scanner class System.out.print("Enter a double value: "); Scanner input= new Scanner(System.in); double d = input.nextDouble(); double d input.nextDouble(); 9/21/2009 CS170, Section 000, Fall 2009 3

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

View Full Document
Chapter 2 Quiz What is the result of ( 1 7 % 4 ) What is the result of ( 2 1 . 5 % 4 ) What is the result of ( 2 1 . 5 % 4 ) What is the value of n and m after each statement? What is the value of n and m after each statement? i n t n = 1 ; i n t m = + + n ; i n t m = + + n + = 3 ; n + = - - m ; n + = m + + ; 9/21/2009 CS170, Section 000, Fall 2009 4
Chapter 3 Selections CS170 Introduction to Computer Science 5

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

View Full Document
Objectives Declare and use boolean types Compare values using relational operators Write Boolean expressions using logic operators Write Boolean expressions using logic operators Implement selection control using if statements I l t l ti t l i it h Implement selection control using switch statements
The Boolean Expressions Use a boolean variable boolean var; // declare a boolean variable var = expression; // assign a boolean value var expression; // assign a boolean value boolean var = expression; // declare and assign A B l i i i th t A Boolean expression is an expression that evaluates to a Boolean value Comparison operators: compare a pair of values (numbers, characters, boolean values) boolean validInput = radius > 0; Boolean operators: perform logic operations 7

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

View Full Document
Comparison Operators Operator Name < less than l th l t <= less than or equal to > greater than >= greater than or equal to == equal to != not equal to 8
Boolean Operators Operator Name ! not && d and || or ^ exclusive or 9

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

View Full Document
Truth Table for Operator ! 10
Truth Table for Operator && 11

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

View Full Document
Truth Table for Operator || 12
Truth Table for Operator ^ 13

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

View Full Document
Example – TestBoolean Scanner input = new Scanner(System.in); int number = input.nextInt(); System.out.println("Is " + number + " divisible by 2 and 3? " + System.out.println( Is + number + divisible by 2 3? + ); System.out.println("Is " + number + " divisible by 2 or 3? " + ); System.out.println("Is " + number + " divisible by 2 or 3, but not both? " + ); /home/cs170000/inclass/sept17/TestBoolean java 14 /home/cs170000/inclass/sept17/TestBoolean.java