Java Reference
In-Depth Information
Display 6.16
Enumerated Type in a switch Statement
Sample Dialogue
What is your favorite flavor?
Vanilla
Classic
Sample Dialogue
What is your favorite flavor?
STRAWBERRY
I bet you said STRAWBERRY.
Sample Dialogue
What is your favorite flavor?
PISTACHIO
This input causes the program to
end and issue an error message.
Self-Test Exercise
22. Rewrite the program in Display 6.15 using a for-each loop.
6.4
Multidimensional Arrays
Two indices are better than one.
ANONYMOUS
Java allows you to declare arrays with more than one index. In this section, we describe
these multidimensional arrays.
Multidimensional Array Basics
It is sometimes useful to have an array with more than one index, and this is allowed
in Java. The following creates an array of characters called page . The array page has
two indices, the first index ranging from 0 to 29 and the second from 0 to 99 .
array
declarations
char [][] page = new char [30][100];
This is equivalent to the following two steps:
char [][] page;
page = new char [30][100];
 
Search WWH ::




Custom Search