tailieunhanh - Lecter Java: Program design - Chapter 5: Decisions

In this chapter, we consider both the if and switch conditional constructs that control whether a statement list is executed. Because the if constructs use logical expressions to determine their course of action, we begin with logical expressions. | Decisions Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Background Our problem-solving solutions so far have the straight-line property They execute the same statements for every run of the program public class DisplayForecast // main(): application entry point public static void main(String[] args) { ("I think there is a world"); (" market for maybe five "); ("computers. “); (" Thomas Watson, IBM, “); ("1943.“); } } Background For general problem solving we need more capabilities The ability to control which statements are executed The ability to control how often a statement is executed We will concentrate first on controlling which statements are executed Java provides the if and switch conditional constructs to control whether a statement list is executed The if constructs use logical expressions to determine their course of action Examination begins . | Decisions Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Background Our problem-solving solutions so far have the straight-line property They execute the same statements for every run of the program public class DisplayForecast // main(): application entry point public static void main(String[] args) { ("I think there is a world"); (" market for maybe five "); ("computers. “); (" Thomas Watson, IBM, “); ("1943.“); } } Background For general problem solving we need more capabilities The ability to control which statements are executed The ability to control how often a statement is executed We will concentrate first on controlling which statements are executed Java provides the if and switch conditional constructs to control whether a statement list is executed The if constructs use logical expressions to determine their course of action Examination begins with logical expressions Logical expressions The branch of mathematics dealing with logical expressions is Boolean algebra Developed by the British mathematician George Boole Logical expressions A logical expression has either the value logical true or logical false Some expressions whose values are logical true The year 2004 is a leap year A meter equals 100 centimeters Some expressions whose values are logical false A triangle has four sides The area of square is always equal to twice its perimeter Logical expressions There are three primary logical operators for manipulating logical values Logical and Logical or Logical not The operators work as most of us would expect Truth tables We use truth tables to give formal specifications of the operators “It works as most of us would expect” allows for ambiguity of interpretation Jim is smiling or Patty is smiling Can both Jim and Patty be smiling? Truth tables Lists all combinations of operand values and the result of the operation for .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.