复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 3 Control Statements

Chapter 3 Control Statements Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs hapter 2 Primitive Data Types and Operations 选择是艰难的 pter 3 Control Statements 谁能控制自己的命运? Chapter 4 Methods apter 5 arrays Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 3 Control Statements Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Control Statements Chapter 5 Arrays Chapter 4 Methods Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Prerequisites for Part I 选择是艰难的 谁能控制自己的命运?

Obiectives To understand the flow of control in selection and loop statements (§32-3.7) To use Boolean expressions to control selection statements and loop statements(§3.2-37) To implement selection control using if and nested if statements (§3.2) To implement selection control using switch statements(s3. 2) To write expressions using the conditional operator(83. 2) To use while, do-while, and for loop statements to control the repetition of statements(s 3. 4) To write nested loops(8.4) To know the similarities and differences of three types of loops (§3.5) To implement program control with break and continue(s 3.6) Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 2 Objectives • To understand the flow of control in selection and loop statements (§3.2-3.7). • To use Boolean expressions to control selection statements and loop statements (§3.2-3.7). • To implement selection control using if and nested if statements (§3.2). • To implement selection control using switch statements (§3.2). • To write expressions using the conditional operator (§3.2). • To use while, do-while, and for loop statements to control the repetition of statements (§3.4). • To write nested loops (§3.4). • To know the similarities and differences of three types of loops (§3.5). • To implement program control with break and continue (§3.6)

Algorithms ● Algorithm O Series of actions in specific order o The actions executed The order in which actions execute ● Program control O Specifying the order in which actions execute o Control structures help specify this order Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 3 Algorithms ⚫Algorithm Series of actions in specific order ⚫The actions executed ⚫The order in which actions execute ⚫Program control Specifying the order in which actions execute ⚫Control structures help specify this order

Pseudocode o Pseudocode OInformal language for developing algorithms ONot executed on computers O Helps developers think out''algorithms O Normally describes only executable statements if student's grade is greater then or equal to 60 Print Passed (grade>=60) System. out. printIn Passed") Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 4 Pseudocode ⚫Pseudocode Informal language for developing algorithms Not executed on computers Helps developers “think out” algorithms Normally describes only executable statements if student’s grade is greater then or equal to 60 Print " Passed" if(grade>=60) System.out.println(“Passed");

Control structures o Sequential execution O Program statements execute one after the other ● Transfer of control o Three control statements can specify order of statements o Sequence structure(built in Java) Selection structure Repetition structure ●F| owchart O Graphical representation of algorithm o flowines indicate order in which actions execute Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 5 Control Structures ⚫ Sequential execution Program statements execute one after the other ⚫ Transfer of control Three control statements can specify order of statements ⚫Sequence structure (built in Java) ⚫Selection structure ⚫Repetition structure ⚫ Flowchart Graphical representation of algorithm ⚫Flowlines indicate order in which actions execute

Flowlines Action Symbols total= total+ grade; counter= counter+ 1 Connector Symbols Flowcharting Javas sequence structure. Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 6 add grade to total total = total + grade; add 1 to counter counter = counter + 1 ; Flowcharting Java’s sequence structure. Flowlines Action Symbols Connector Symbols

Decision Symbol true grade >=60 print Passed false Flowcharting the single-selection if structure Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 7 grade >= 60 true false print “Passed” Flowcharting the single-selection if structure. Decision Symbol

Selection Statements >if Statements switch statements Conditional Operators Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 8 Selection Statements ➢ if Statements ➢ switch Statements ➢ Conditional Operators

Simple if Statements if (radius >=0)3 area radius radius PI if(booleanExpression)i System. out. println("The area"+ statement(s) for the circle of radi radius +iS"+ area false false E Statement(s) System. out println("The area for the circle of " radius"+radius +"is"+ area (A) Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 9 Simple if Statements Boolean Expression true Statement(s) false (radius >= 0) true area = radius * radius * PI; System.out.println("The area for the circle of " + "radius " + radius + " is " + area); false (A) (B) if (booleanExpression) { statement(s); } if (radius >= 0) { area = radius * radius * PI; System.out.println("The area" + “ for the circle of radius " + radius + " is " + area); }

Note Outer parentheses required Braces can be omitted if the block contains a single f((i>0)&&(i0)&&(i 10)) System. out. printin("i isan integer between 0 and 10")i integer between 0 and 10)i Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 10 Note if ((i > 0) && (i 0) && (i < 10)) System.out.println("i is an " + + "integer between 0 and 10"); Outer parentheses required Braces can be omitted if the block contains a single statement
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 2 Primitive Data Types and Operations.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 1 Introduction to Computers, Programs, and Java.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 0 course intro Programming Language(Using Java).ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)Game of Life_题目要求.pdf
- 复旦大学:《程序设计》课程教学资源(Java Lab)Game of Life.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)验证哥德巴赫猜想.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)Ansi Temple.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)富人Smith的生日 If else Switch.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)3.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)环境配置与第一个程序的运行.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)第一个java程序.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter8 Conclusion and Outlook.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter7 Ontology Engineering.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter6 Applications.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter5 Logic and Inference:Rules.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter4 Web Ontology Language:OWL.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter3 Describing Web Resources in RDF.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter2 Structured Web Documents in XML.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter1 The Semantic Web Vision.ppt
- 《高级Web技术》参考资料:语义Web A Semantic Web Primer.pdf
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 4 Methods.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 5 Arrays.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 6 Objects and Classes.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 7 String.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 8 Inheritance and Polymorphism.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 9 Abstract Classes and Interfaces.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 10 Object-Oriented Modeling(oom).ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 11 Getting Started with GUI Programming.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 12 Event-Driven Programming.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 13 Creating User Interfaces.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 14 Applets, Images, and Audio.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 15 Exceptions and Assertions.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 16 Simple Input and Output.ppt
- 复旦大学:《信息安全》教学课件_01 Classical Encryption Techniques.pdf
- 复旦大学:《信息安全》教学课件_02 Classical Encryption Techniques(cont.).pdf
- 复旦大学:《信息安全》教学课件_03 Modern Block Ciphers.pdf
- 复旦大学:《信息安全》教学课件_04 Public Key Cryptography, RSA.pdf
- 复旦大学:《信息安全》教学课件_05 Message authentication and Hash function.pdf
- 复旦大学:《信息安全》教学课件_06 The Intro to Information Security.pdf
- 复旦大学:《信息安全》教学课件_07-08 Public Key Infrastructure(PKI)公钥基础设施——公钥技术的应用.pdf