Question | Value |
1 | 25 |
2 | 25 |
3 | 25 |
4 | 25 |
Total | 100 |
1. What is the value of variables i, j, and k after the statements below have been executed?
j -= j;
k += --i + 5;
i *= i % 4;
3. Convert
the following code fragment to an equivalent one that uses for statements
in place of the while statements. If this cannot be done,
explain why.
System.out.println("Begin
computation of various values of e");
while (i <= 10)
{
n = 1;
x *= -i;
e2x = term = 1.0;
System.out.println(i + ": x = " + x);
while (n <= limit) {
term *= x/n;
e2x += term;
System.out.println(" " + n + ": term = " + term + ",
e2x = " + e2x );
n++;
}
i++;
System.out.println(" End computation of e to " + x);
}
System.out.println("End
computation of various values of e");
4. Complete
the following skeletal applet so that it produces a "bull's eye".
The bull's eye is centered on pixel (150, 150). The inner circle
is of radius 40 pixels, and is black. The middle ring is white
and is 40 pixels wide. The outer ring is black and is 40 pixels
wide.
public class bullsEye extends Applet {
public void paint( Graphics
g ) {
}
}