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;
Solution: j = 0, k = 75, i = 12.
2. Write java statement[s] that assign 7 to int variable j, if the value of int variable i is evenly divisible by 2 and 3 and is evenly divisible by neither 5 nor 7, and assigns -7 to int variable j otherwise. Do not use boolean operators.
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");
int i, limit = 8, n;
double x = 1.0, term, e2x;
System.out.println("Begin computation of various values of e");
for (i = 1; i <= 10; i++) {
x *= -i;
e2x = term = 1.0;
System.out.println(i + ": x = " + x);
for (n = 1; n <= limit; n++) {
term *= x/n;
e2x += term;
System.out.println(" " + n + ": term = " + term + ",
e2x = " + e2x );
}
System.out.println(" End computation of e to " + x);
}
System.out.println("End computation of various values of e");
public class bullsEye extends Applet {
public void paint( Graphics
g ) {
}
}
import java.awt.*;
import java.applet.*;
public class bullsEye extends Applet {
public void paint(Graphics
g) {
g.fillOval(30, 30, 240, 240);
g.setColor(Color.white);
g.fillOval(70, 70, 160, 160);
g.setColor(Color.black);
g.fillOval(110, 110, 80, 80);
}
}