Java Reference
In-Depth Information
case 1:
case 3:
case 5:
case 7:
odd ++;
for (int i2 = 0; i2 < 10; i2++) {
odd++;
break
outerloop
;
}
break;
case 2:
case 4:
case 6:
case 8:
even ++;
break;
default:
other ++;
break;
}
}
System.out.println ("Odd, Even, Other, and Total = " + odd + ", " +
even + ", " + other + ", " + total);
Compile and rerun the HelloWorld application. The output should look
like this:
...
Odd, Even, Other, and Total = 2, 0, 1, 2
Look closely at the labeled
for
loop definition and the output line. How
many times did the outer
for
loop execute this time? Why do you think
that the variable named
Even
was never incremented in the loop?
R
EVIEWING THE
E
XERCISES
Let's review the samples you've created. Try to relate the sample source statements
to the result (that is, the output) each statement creates. If necessary, rerun the sam-
ples, or look at the complete source code for this exercise on the CD-ROM. Feel free
to experiment by yourself.