26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Contents IX<br />

5 Control Structures: Part 2 197<br />

5.1 Introduction 198<br />

5.2 Essentials of Counter-Controlled Repetition 198<br />

5.3 The for Repetition Structure 201<br />

5.4 Examples Using the for Structure 205<br />

5.5 The switch Multiple-Selection Structure 210<br />

5.6 The do/while Repetition Structure 215<br />

5.7 Statements break and continue 218<br />

5.8 Labeled break and continue Statements 220<br />

5.9 Logical Opera<strong>to</strong>rs 222<br />

5.10 Structured <strong>Program</strong>ming Summary 229<br />

5.11 (Optional Case Study) Thinking About Objects: Identifying<br />

Objects’ States and Activities 234<br />

6 Methods 246<br />

6.1 Introduction 247<br />

6.2 <strong>Program</strong> Modules in <strong>Java</strong> 247<br />

6.3 Math Class Methods 249<br />

6.4 Methods 249<br />

6.5 Method Definitions 251<br />

6.6 Argument Promotion 258<br />

6.7 <strong>Java</strong> API Packages 259<br />

6.8 Random-Number Generation 261<br />

6.9 Example: A Game of Chance 265<br />

6.10 Duration of Identifiers 274<br />

6.11 Scope Rules 275<br />

6.12 Recursion 278<br />

6.13 Example Using Recursion: The Fibonacci Series 281<br />

6.14 Recursion vs. Iteration 286<br />

6.15 Method Overloading 288<br />

6.16 Methods of Class JApplet 291<br />

6.17 (Optional Case Study) Thinking About Objects: Identifying<br />

Class Operations 293<br />

7 Arrays 313<br />

7.1 Introduction 314<br />

7.2 Arrays 315<br />

7.3 Declaring and Allocating Arrays 317<br />

7.4 Examples Using Arrays 317<br />

7.4.1 Allocating an Array and Initializing Its Elements 318<br />

7.4.2 Using an Initializer List <strong>to</strong> Initialize Elements of an Array 319<br />

7.4.3 Calculating the Value <strong>to</strong> S<strong>to</strong>re in Each Array Element 320<br />

7.4.4 Summing the Elements of an Array 322<br />

7.4.5 Using His<strong>to</strong>grams <strong>to</strong> Display Array Data Graphically 323<br />

7.4.6 Using the Elements of an Array as Counters 324<br />

7.4.7 Using Arrays <strong>to</strong> Analyze Survey Results 326<br />

© Copyright 2002 by Prentice Hall. All Rights Reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!