lecture7-chapter3

lecture7-chapter3 - Lecture 7: Chapter 3 Review CS 170,...

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

View Full Document Right Arrow Icon
Lecture 7: Chapter 3 Review CS 170, Section 000, Fall 2009 17 September 2009
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture Plan Logistics (important announcements) Chapter 2 “quiz” W1 Questions? HW1 Questions? Chapter 3 review 9/21/2009 CS170, Section 000, Fall 2009 2
Background image of page 2
2.13: Scanner class System.out.print("Enter a double value: "); Scanner input= new Scanner(System.in); ouble d = input.nextDouble(); double d input.nextDouble(); 9/21/2009 CS170, Section 000, Fall 2009 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
Chapter 2 Quiz What is the result of ( 1 7 % 4 ) hat is the result of 21.5 % 4) What is the result of (21.5 % 4) hat is the value of n and m after each statement? What is the value of n and m after each statement? int n = 1 ; t m =++ n; int m =++ n+=3; n+= --m ; n+= m++; 9/21/2009 CS170, Section 000, Fall 2009 4
Background image of page 4
Chapter 3 Selections CS170 troduction to Computer Science 5 Introduction to Computer Science
Background image of page 5

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

View Full DocumentRight Arrow Icon
Objectives Declare and use boolean types Compare values using relational operators rite Boolean expressions using logic operators Write Boolean expressions using logic operators Implement selection control using if statements Implement selection control using switch statements
Background image of page 6
The Boolean Expressions Use a boolean variable boolean var; // declare a boolean variable r = expression; // assign a boolean value var expression; // assign a boolean value boolean var = expression; // declare and assign 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
Comparison Operators Operator Name < less than t h l t <= less than or equal to > greater than >= greater than or equal to == equal to = not equal to 8 ! ot equa to
Background image of page 8
Boolean Operators Operator Name ! not & d && and || or ^ exclusive or 9
Background image of page 9

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

View Full DocumentRight Arrow Icon
Truth Table for Operator ! 10
Background image of page 10
Truth Table for Operator && 11
Background image of page 11

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

View Full DocumentRight Arrow Icon
Truth Table for Operator || 12
Background image of page 12
Truth Table for Operator ^ 13
Background image of page 13

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

View Full DocumentRight Arrow Icon
Example – TestBoolean Scanner input = new Scanner(System.in); int number = input.nextInt(); ystem.out.println("Is " + number + " divisible by 2 nd ? " + System.out.println( Is + number + divisible by 2 and 3? + ); System.out.println("Is " + number + " divisible by 2 or 3? " + ); System.out.println("Is " + number + " divisible by 2 or 3, but not both? " + ); ome/cs170000/inclass/sept17/TestBoolean java 14 /home/cs170000/inclass/sept17/TestBoolean.java
Background image of page 14
Boolean Expressions Evaluation Java uses shortcut evaluation - evaluation of boolean expression stops as soon as the result is known, which makes code execute faster than if all boolean operands were evaluated. int x = 0; if ( x > 0 && x++ < 5) x = x - 1;
Background image of page 15

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

View Full DocumentRight Arrow Icon
Problem: Determining Leap Year? Write a program that determines if given year is a leap year Read input year ompute whether input year is a leap year Compute whether input year is a leap year - a year is a leap year if it is divisible by 4 but not by 00 or if it is divisible by 400 100 or if it is divisible by 400 Display the result 16 /home/cs170000/inclass/sept17/LeapYear.java
Background image of page 16
Exercise: A Simple Math Learning ol Tool Write a program to let a first grader practice additions
Background image of page 17

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

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

Page1 / 53

lecture7-chapter3 - Lecture 7: Chapter 3 Review CS 170,...

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

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