Recitation5

Recitation5 - CS180 Recitation CS180 gta Feb 10, 2012...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: CS180 Recitation CS180 gta Feb 10, 2012 Selection Statements if block 1 i f ( boolean expression ) { 2 // if condition evaluated to true 3 } if..else block 1 i f ( boolean expression ) { 2 // if condition evaluated to true 3 } else { 4 // if condition evaluated to false 5 } Selection Statements Examples if block 1 int a = 10; 2 int b = 20; 3 i f ( a > b ) { 4 System . out . p r i n t l n ( a i s greater than b ) ; 5 } if..else block 1 int a = 10; 2 int b = 20; 3 i f ( a > b ) { 4 System . out . p r i n t l n ( a i s greater than b ) ; 5 } else { 6 System . out . p r i n t l n ( a i s less than or equal to b ) ; 7 } Selection Statements Examples if else chain 1 int a = 10; 2 i f ( a > 90) { 3 System . out . p r i n t l n ( a i s greater than 90 ) ; 4 } else i f ( a > 80) { 5 System . out . p r i n t l n ( a > 80 , but < = 90 ) ; 6 } else i f ( a > 70) { 7 System . out . p r i n t l n ( a > 70 , but < = 80 ) ; 8 } else i f ( a > 60) { 9 System . out . p r i n t l n ( a > 60 , but < = 70 ) ; 10 } Selection Statements Examples if else nesting 1 i f ( a > 90) { 2 i f ( b < 50) { 3 i f ( c > 30) 4 System . out . p r i n t ( a > 90 b < 50 and c > 30 ) ; 5 } 6 } Are these equivalent? 1 i f ( a > 90 && b < 50 && c > 30) { 2 System . out . p r i n t ( a > 90 b < 50 and c > 30 ) ; 3 } Selection Statements Given three values, find the max 1 i f ( a > b ) { 2 i f ( a > c ) { 3 System . out . p r i n t l n ( Max i s + a ) ; 4 } else { // c >= a 5 System . out . p r i n t l n ( Max i s + c ) ; 6 } 7...
View Full Document

Page1 / 21

Recitation5 - CS180 Recitation CS180 gta Feb 10, 2012...

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

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