第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节)