19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

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

152 Chapter 4 Loops<br />

nested loop<br />

table title<br />

outer loop<br />

inner loop<br />

Key<br />

Point<br />

4.6 Nested Loops<br />

A loop can be nested inside another loop.<br />

Nested loops consist of an outer loop and one or more inner loops. Each time the outer loop is<br />

repeated, the inner loops are reentered, and started anew.<br />

Listing 4.7 presents a program that uses nested for loops <strong>to</strong> display a multiplication table.<br />

LISTING 4.7<br />

MultiplicationTable.java<br />

1 public class MultiplicationTable {<br />

2 /** Main method */<br />

3 public static void main(String[] args) {<br />

4 // Display the table heading<br />

5 System.out.println(" Multiplication Table");<br />

6<br />

7 // Display the number title<br />

8 System.out.print(" ");<br />

9 for (int j = 1; j

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

Saved successfully!

Ooh no, something went wrong!