Page 184 - Introduction to Programming with Java: A Problem Solving Approach
P. 184
150 Chapter 4 Control Statements 15. Happy birthday as a for loop:
for (int age=0; age < 5; age++)
{
System.out.println("Happy Birthday# " + age);
} // end for
Output:
Happy
Birthday# 0
Birthday# 1
Birthday# 2
Birthday# 3
Birthday# 4
Happy
Happy
Happy
Happy
16. A do loop is most appropriate in simple situations where there will always be at least one pass.
17. Template for a pair of nested for loops: for (int i=0; i<imax; i++) {
}
{
<statement(s)>
} // end for j // end for i
for (int j=0; j<jmax; j++)
18. A for loop representation of a while loop:
for (boolean OK=falAsep;a!OgK;o) PDFEnhancer {
<statement(s)>
}
19. Given the expression: !(!a || !b)
Starting on the left side of basic identity 16 and going to the right side gives this:
!!a && !!b
Then using basic identity 1 gives this:
a && b