Java Reference
In-Depth Information
float[][] matrix = { { 1.0F, 2.0F, 3.0F }, { 4.0F, 5.0F,
6.0F }};
for (int row = 0; row < matrix.length; row++)
for (int col = 0; col < matrix[row].length; col++)
System.out.print(matrix[row][col]+" ");
Expression matrix.length returns the number of rows in this tabular array. For
each row, expression matrix[row].length returns the number of columns for
that row. This latter expression suggests that each row can have a different number of
columns, although each row has the same number of columns in the example.
System.out.print() iscloselyrelatedto System.out.println() .Unlike
the latter method, System.out.print() outputs its argument without a trailing
This example generates the following output:
1.0 2.0 3.0
4.0 5.0 6.0
While Statement
uates to true. This statement has the following syntax:
while ( Boolean expression )
While consists of reserved word while , followed by a parenthesized Boolean
expression header, followed by a statement to repeatedly execute.
Thewhilestatementfirstevaluatesthe Boolean expression .Ifitistrue,while
executes the other statement . Once again, the Boolean expression is evalu-
ated. If it is still true, while re-executes the statement . This cyclic pattern continues.
ter or its lowercase equivalent. The following example provides a demonstration:
int ch = 0;
while (ch != 'C' && ch != 'c')
Search WWH ::

Custom Search