Page 181 - Introduction to Programming with Java: A Problem Solving Approach
P. 181

                6. [after §4.12] Given this main method:
1
public static void main(String[] args)
2{
3
for (int start=1; start<=5; start+=2)
4{
5
for (int count=start; count>=1; count--)
6{
7
System.out.print(count + " ");
8}
9
10 }
System.out.println("Liftoff!");
11 } // end main
Trace the code using either the short form or the long form. To help you get started, here’s the trace setup. For the short form, you won’t need the line# column.
7. [after §4.13] Given this main method:
Exercises 147
 line#
 start
 count
 output
 1
public static void main(String[] args)
2{
3
boolean sheLovesMe = true;
4
for (intAnpuma=0g; onum<P4;DnFum++E) nhancer 6{
5
7
sheLovesMe = !sheLovesMe;
8}
9
10
if (sheLovesMe)
11
System.out.println("She loves me!");
12
}
13
else
14
{
15
System.out.println("She loves me not!");
16
}
17
}
// end main
{
Trace the code using either the short form or the long form. To help you get started, here’s the trace setup. For the short form, you won’t need the line# column.
8. [after §4.13] Consider the BowlingScores program below. /*************************************************************
 line#
 sheLovesMe
 num
 output
 *
BowlingScores.java
Dean & Dean
This implements a bowling scores algorithm.
*
*
*
*************************************************************/































   179   180   181   182   183