BPJ 04-06 Quiz
-
What is the value of
b
in the Java program below?int b = 5 + 1 / 6 + 2 * (5 / 6);
-
What is the output of the code segment below?
int c = 60; int d = 8; System.out.println(c % (++d));
-
What is the value of
g
in the segment below?double g = -1; g = (int)(3.0 + 4)/(1 + 4.0) * 2 - 3;
-
Is the code below allowed?
int x = 7; x += 1.93;
- Yes, the answer is 9.
- Yes, the answer is 8.
- No, you cannot add an int plus a double.
- No, you cannot store a double in an int.
-
Is
double h6 = 83;
legal? -
What is the result?
double r = (double) (30/4); System.out.println(r);
-
What is the result?
int s = 31 % 4; int t = 17 / 5; double ans = s + t; System.out.println(ans);
-
Is this legal? Include a fix if not. Answer: “yes” or “no, (fix here)”.
int u = Math.abs(-19.7);
-
Is this legal? Include a fix if not. Answer: “yes” or “no, (fix here)”.
double v = Math.cos(0.125);
-
Write a short program to get the computer to print out the mathematical computation and its integer result.
50 + 30 / 60 + 8 * 13 / 7 + 1234 * (-4321)
-
Write a segment of code that declares an appropriate variable
w
and initializes it with the following value. Have the computer do the math.$$ 3 \pi \cos(60^\circ) + 1.75^4 $$
Using $\cos(60^\circ) = 0.5$, this evaluates to 14.091…