中国高校课件下载中心 》 教学资源 》 大学文库

《Java程序设计》课程教学课件(PPT讲稿)第4章 循环

文档信息
资源类别:文库
文档格式:PPT
文档页数:48
文件大小:254.5KB
团购合买:点击进入团购
内容简介
《Java程序设计》课程教学课件(PPT讲稿)第4章 循环
刷新页面文档预览

第4章循环Liang,Introduction to Java Programming,Eighth Edition, (c)2011 PearsonEducation, Inc.All rights reserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 第4章 循 环

引言(例如:假设你需要打印一个字符串“Welcome to Java!100次。这就需要把下面的输出语句重复100遍,过程是相当繁琐:System.out.println("Welcome to Java!"):所以,该如何解决这个问题?Liang,Introduction toJava Programming.EighthEdition,(c)2011Pearson Education,Inc.Allrightsreserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 2 引言 假设你需要打印一个字符串 (例如: “Welcome to Java!”)100次。这就需要把下面的 输出语句重复100遍,过程是相当繁琐: System.out.println("Welcome to Java!"); 所以,该如何解决这个问题?

开放问题问题:System.out.println("welcometoJavaSystem.out.println("welcomeJava!toSystem.out.println("welcomeJava!"TOJava!")System.out.println("welcometoJava!")System.out.println("welcometoJava!");System.out.println("welcomeeto100次System.out.println("welcome toJava!");System.out.println("welcome to Java!");System.out.println("welcome toJava!");Liang,Introduction to Java Programming,Eighth Edition,(c)2011Pearson Education,Inc.Allrightsreserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 3 开放问题 System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!"); . . . System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!"); System.out.println("Welcome to Java!"); 问题: 100次

介绍while循环int count = o;while (count < 100)System.out.println("welcome to Java") ;count++;Liang,Introduction toJava Programming.EighthEdition,(c)2011Pearson Education,Inc.Allrightsreserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 4 介绍while循环 int count = 0; while (count < 100) { System.out.println("Welcome to Java"); count++; }

学习目标使用while循环编写重复执行某些语句的程序(第4.2节)开发程序GuessNumber(第4.2.1节)遵循循环设计策略来开发(第4.2.2节)开发程序SubtractionQuizLoop(第4.2.3节)。使用标志值控制循环(第4.2.3节)。使用输入重定向而不是从键盘输入以获得大量输入(第4.2.4节)使用do-while语句编写循环(第4.3节)使用for语句编写循环(第4.4节)。了解三种类型的循环语句相似处和不同点(第4.5节)编写嵌套循环(第4.6)。学习最小化数值误差的技术(第4.7节)从多种多样的例子(GCD、FutureTuition、MonteCarloSimulation)中学习循环(第4.8节)使用break和continue实现程序的控制(第4.9节)(GUI)使用确认对话框控制循环(第4.10节)Liang,Introduction to Java Programming,EighthEdition,(c)2011PearsonEducation,Inc.All rights reserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 5 学习目标 使用while循环编写重复执行某些语句的程序 (第4.2节)。 开发程序 GuessNumber(第4.2.1节)。 遵循循环设计策略来开发(第4.2.2节)。 开发程序SubtractionQuizLoop (第4.2.3节)。 使用标志值控制循环 (第4.2.3节)。 使用输入重定向而不是从键盘输入以获得大量输入(第4.2.4节)。 使用do-while语句编写循环(第4.3节)。 使用for语句编写循环(第4.4节)。 了解三种类型的循环语句相似处和不同点(第4.5节)。 编写嵌套循环(第4.6)。 学习最小化数值误差的技术(第4.7节)。 从多种多样的例子(GCD、FutureTuition、MonteCarloSimulation)中学 习循环(第4.8节)。 使用break和continue实现程序的控制(第4.9节)。 (GUI)使用确认对话框控制循环(第4.10节)

while 循环流程图int count = O:(循环继续条件)whilewhile (count<100) {Ⅱ循环体System.out.println("WelcometoJava!")语句(组)count++:count=0.LoopfalsefalseContinuation(count<100)?Condition?truetrueStatement(s)System.out.println("WelcometoJava!"(loopbody)count++,vO(B)(A)Liang,Introduction to Java Programming,Eighth Edition,(c)2011Pearson Education,Inc.Allrightsreserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 6 while 循环流程图 while (循环继续条件){ // 循环体; 语句(组); } int count = 0; while (count < 100) { System.out.println("Welcome to Java!"); count++; } Loop Continuation Condition? true Statement(s) (loop body) false (count < 100)? true System.out.println("Welcome to Java!"); count++; false (A) (B) count = 0;

动画跟踪while循环初始化countint count = O:while (count < 2) System.out.println("Welcome to Java!");count++:Liang.Introduction to JavaProgramming.EighthEdition,(c)2011Pearson Education,Inc.Allrightsreserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 7 跟踪while循环 int count = 0; while (count < 2) { System.out.println("Welcome to Java!"); count++; } 初始化 count 动 画

动画(续)跟踪while循环(count<2)为真int count = O:while(count<2)System.out.println("Welcome to Java!");count++:Liang.Introduction to JavaProgramming.EighthEdition,(c)2011Pearson Education,Inc.Allrightsreserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 8 跟踪while循环(续) int count = 0; while (count < 2) { System.out.println("Welcome to Java!"); count++; } (count < 2) 为真 动 画

动画(续)跟踪while 循环输出WelcometoJavaint count = O:while (count < 2) System.out.println("WelcometoJava!"count++:Liang,Introduction toJava Programming,EighthEdition,(c)2011Pearson Education,Inc.Allrightsreserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 9 跟踪 while 循环(续) int count = 0; while (count < 2) { System.out.println("Welcome to Java!"); count++; } 输出 Welcome to Java 动 画

动画(续)跟踪while循环count自增1int count = O:现在count是1while (count < 2) (System.out.println("Welcome to Java!count++:Liang,Introduction toJava Programming,EighthEdition,(c)2011Pearson Education,Inc.All10rightsreserved.0132130807

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 10 跟踪 while 循环(续) int count = 0; while (count < 2) { System.out.println("Welcome to Java!"); count++; } count自增1 现在count 是1 动 画

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档