Welcome to the Unit 1 Foundation Practice Assessment. This 20-question assessment focuses on foundational Java concepts currently covered in this practice collection, including variables, arithmetic expressions, casting, remainder operations, and compound assignment.
Exam Instructions: You have roughly 2 minutes per question. Have scratch paper ready to trace variable updates. Pay close attention to integer division, casting, operator precedence, remainder operations, and compound assignment.
Unit 1 Foundation Practice Assessment
int b = 2;
double result = a / b;
System.out.println(result);
a and b are both integers,
a / b performs integer division first.
7 / 2 truncates to 3.
After the integer division evaluates, the result is implicitly widened
to a double (3.0) and stored in result.double variable myVal to the nearest integer?(int) truncates
the decimal portion, completing the rounding process.x *= 2 + 4;
System.out.println(x);
x *= 2 + 4; translates to
x = x * (2 + 4);. Thus, 5 * 6 evaluates to 30.2.System.out.println(num1 + num2);
int num1, num2 = 10; declares both variables
but only initializes num2. Because num1 is
uninitialized, trying to add it causes a compile-time error.System.out.println(result);
4 / 2 evaluates to 2.
The expression becomes 8 - 2 + 1.
Subtraction and addition are evaluated left to right:
6 + 1 equals 7.(5 + 2) force the mathematical
addition to occur first, yielding 7.
That integer is then concatenated to the String.17 / 5 has quotient 3 with remainder 2,
so 17 % 5 is 2.int val = 8;. Which of the following accurately
subtracts 1 from val?II. val -= 1;
III. val–;
int truncated = (int) value;
System.out.println(truncated);
double to an int completely
discards the decimal portion without rounding.
5.99 simply truncates to 5.20 / 3 evaluates to 6
via integer division. Then, 6 * 2 evaluates to 12.double to an int
because it results in a loss of precision. A compilation error is thrown
unless explicit casting is used.int y = 10;
System.out.println(x % y);
7) as the remainder.System.out.println(result);
(double) is immediately adjacent to the
15, it casts the 15 to 15.0 before the division occurs.
The operation 15.0 / 4 forces floating-point division, yielding
3.75.k += 4;
k %= 5;
System.out.println(k);
k += 4; updates k to 12.2.
k %= 5; evaluates the remainder of 12 divided by 5,
which is 2.45) from the integer
num = 8245;?8245 % 100 divides by 100 and returns the
remainder, which is 45.value *= 3 + 1;
System.out.println(value);
value *= 3 + 1; is equivalent to
value = value * (3 + 1);. Therefore, 6 * 4 = 24.int b = a;
b++;
System.out.println(a + ” ” + b);
int b = a; executes, the value of a is
copied into b. Incrementing b later does not
change a, so the output is 3 4.int num = 10;
num = LIMIT – 5;
System.out.println(num);
final keyword prevents LIMIT from being changed,
but its value (50) can be read and used in mathematical operations.
LIMIT - 5 evaluates to 45, which is legally stored in the
non-final variable num.result?12.5 % 3 is 0.5.
Casting 0.5 to int gives 0,
and then 0 + 2 gives 2.Congratulations on Completing Unit 1!
If you scored 18 or higher, you have demonstrated strong command of the foundational concepts covered in this practice assessment. Review any questions you missed and continue with the current Unit 1 practice topics.
These foundational Java concepts support the rest of AP Computer Science A. Continue with the current Unit 1: Using Objects and Methods practice to work on the remaining Unit 1 topics.