tailieunhanh - Lecture Introduction to Java programming - Chapter 3: Selections

If you assigned a negative value for radius in Listing , , the program would print an invalid result. If the radius is negative, you don't want the program to compute the area. How can you deal with this situation? On completion of this chapter students will know how to: To declare boolean type and write Boolean expressions using comparison operators, to program AdditionQuiz using Boolean expressions, to implement selection control using one-way if statements,. | Chapter 3 Selections Motivations If you assigned a negative value for radius in Listing , , the program would print an invalid result. If the radius is negative, you don't want the program to compute the area. How can you deal with this situation? Objectives To declare boolean type and write Boolean expressions using comparison operators (§). To program AdditionQuiz using Boolean expressions (§). To implement selection control using one-way if statements (§) To program the GuessBirthday game using one-way if statements (§). To implement selection control using two-way if statements (§). To implement selection control using nested if statements (§). To avoid common errors in if statements (§). To program using selection statements for a variety of examples (BMI, ComputeTax, SubtractionQuiz) (§). To generate random numbers using the () method (§). To combine conditions using logical operators (&&, ||, and !) (§). To program using selection statements with combined conditions (LeapYear, Lottery) (§§). To implement selection control using switch statements (§). To write expressions using the conditional operator (§). To format output using the method and to format strings using the method (§). To examine the rules governing operator precedence and associativity (§). (GUI) To get user confirmation using confirmation dialogs (§). The boolean Type and Operators Often in a program you need to compare two values, such as whether i is greater than j. Java provides six comparison operators (also known as relational operators) that can be used to compare two values. The result of the comparison is a Boolean value: true or false. boolean b = (1 > 2); Comparison Operators Operator Name greater than >= greater than or equal to == equal to != not equal to Problem: A Simple Math Learning Tool . | Chapter 3 Selections Motivations If you assigned a negative value for radius in Listing , , the program would print an invalid result. If the radius is negative, you don't want the program to compute the area. How can you deal with this situation? Objectives To declare boolean type and write Boolean expressions using comparison operators (§). To program AdditionQuiz using Boolean expressions (§). To implement selection control using one-way if statements (§) To program the GuessBirthday game using one-way if statements (§). To implement selection control using two-way if statements (§). To implement selection control using nested if statements (§). To avoid common errors in if statements (§). To program using selection statements for a variety of examples (BMI, ComputeTax, SubtractionQuiz) (§). To generate random numbers using the () method (§). To combine conditions using logical operators (&&, ||, and !) (§).

TÀI LIỆU MỚI ĐĂNG