Relational Operators //less than //less than or equal to equal to //not equal to //greater than //greater than or equal to <80 testScore 2>=350 2大Math. PI radi 359.99 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 6-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 6 testScore < 80 testScore * 2 >= 350 30 < w / (h * h) x + y != 2 * (a + b) 2 * Math.PI * radius <= 359.99 Relational Operators < //less than <= //less than or equal to == //equal to != //not equal to > //greater than >= //greater than or equal to
Compound statements r Use braces if the <then> or <else> block has multiple statements if (testscore 70 messageBox. show("You did not pass")i Then block messageBox. show(Try harder next time")i else messageBox. show("You did pass")i Else block message Box. show("Keep up the good work")i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 7 if (testScore < 70) { messageBox.show("You did not pass"); messageBox.show("Try harder next time"); } else { messageBox.show("You did pass"); messageBox.show("Keep up the good work"); } Compound Statements Use braces if the <then> or <else> block has multiple statements. Then Block Else Block
Style guide f( <boolean expression>) else I Style 1 f( <boolean expression> Style 2 else C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 6-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 8 if ( <boolean expression> ) { … } else { … } Style Guide if ( <boolean expression> ) { … } else { … } Style 1 Style 2
The if-then statement if( <boolean expression> <then block> Boolean Expression testscore >=95 ····························································· Then block messageBox show("You are an honor student)i C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6-9
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 9 The if-then Statement if ( testScore >= 95 ) messageBox.show("You are an honor student"); if ( <boolean expression> ) <then block> Then Block Boolean Expression
Control flow of if-then true testscore > 95? messageBox. show false C You are an honor student); C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 6-10
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 6 - 10 Control Flow of if-then testScore >= 95? false messageBox.show ("You are an honor student"); true