tailieunhanh - Lecture Java methods: Object-oriented programming and data structures (3rd AP edition): Chapter 7 - Maria Litvin, Gary Litvin

Chapter 7 - Boolean expressions and if-else statements. This chapter also includes relational and logical operators, De Morgan’s Laws, the switch statement and enum data types. Another objective is to discuss team development and illustrate software reusability in the context of a simple but realistic case study, the Craps project. | Algorithms and Iterations while (chapter 7- Java also has a “for each” loop for traversing lists and other structures. It is explained later, in Chapters 9, 11, and 20. Objectives: Understand general properties of algorithms Get familiar with pseudocode and flowcharts Learn about iterations Understand the semantics and learn the Java syntax for while, for, and do-while loops Learn how to use nested loops 7- Also learn about perfect numbers. Define Algorithm. Hard to define formally A more or less compact, general, and abstract step-by-step recipe that describes how to perform a certain task or solve a certain problem. Examples: Long division Euclid’s Algorithm for finding the greatest common factor (circa 300 BC) Binary Search (guess-the-number game) 7- . | Algorithms and Iterations while (chapter 7- Java also has a “for each” loop for traversing lists and other structures. It is explained later, in Chapters 9, 11, and 20. Objectives: Understand general properties of algorithms Get familiar with pseudocode and flowcharts Learn about iterations Understand the semantics and learn the Java syntax for while, for, and do-while loops Learn how to use nested loops 7- Also learn about perfect numbers. Define Algorithm. Hard to define formally A more or less compact, general, and abstract step-by-step recipe that describes how to perform a certain task or solve a certain problem. Examples: Long division Euclid’s Algorithm for finding the greatest common factor (circa 300 BC) Binary Search (guess-the-number game) 7- Fundamental concepts are often hard to define! Tools for Describing Algorithms Pseudocode A sequence of statements, more precise notation Not a programming language, no formal syntax Flowcharts Graphical representation of control flow 7- In pseudocode and flowcharts we do not use data types for variables (such as int, double, etc.); in Java we do. Example: calculate 12 + 22 + . + n2 Pseudocode Input: n sum 0 k 1 Repeat the following three steps while k n: sq k * k sum sum + sq k k + 1 Output: sum A B Set A to the value of B 7- The “repeat” statement is what makes this algorithm compact. Example (cont’d) Flowchart n sum 0 k 1 k n ? sq k * k sum sum + sq k k + 1 sum No Yes Input / output Processing step Decision 7- Flowcharts are pretty much history: they are really not used in software development any more since most software development has switched to OOP. Another Example: 1. Start at pos0, facing dir0 2. If wall in front, turn 90º clockwise else go .

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.