• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar

JavaTutorOnline

1-on-1 Online Java Training by a Senior Software Engineer

  • Home
  • AP CSA
    • FRQ Practice
      • Arrays
      • ArrayList
      • Strings
      • 2D Arrays
    • MCQ Practice
      • Booleans
      • Iteration
      • Arrays
      • View all Units
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • CONTACT US

AP CSA Unit 1.5 & 1.6 MCQ Practice | JavaTutorOnline

Home » AP CSA MCQ » Unit 1: Using Objects and Methods » Casting & Compound Assignment

AP CSA Unit 1.5 & 1.6 MCQ Practice: Casting & Compound Assignment

📚 Topics 1.5–1.6 ⏱️ 25 Min Practice ✅ Current AP CSA Framework

Explicit casting and compound assignment operators are important parts of Java expression evaluation. AP Computer Science A questions can test how casting changes a value, how compound assignment updates a variable, and how post-increment and post-decrement affect numeric variables.

In this interactive practice set, we cover AP CSA Topics 1.5 and 1.6: Casting and Range of Variables, and Compound Assignment Operators. These 15 multiple-choice questions cover casting, integer range, rounding, compound assignment, and post-increment and post-decrement operators.

Key Concepts to Remember Before You Start:

  • Casting: The casting operators (int) and (double) can convert primitive values in arithmetic expressions. Casting a double to an int truncates the digits to the right of the decimal point.
  • Rounding: For a non-negative double, (int)(x + 0.5) rounds to the nearest integer. For a negative double, (int)(x - 0.5) rounds to the nearest integer.
  • Compound Assignment: The operators +=, -=, *=, /=, and %= perform the indicated arithmetic operation and assign the result back to the variable on the left.
  • Integer Range: Java int values have a finite range from Integer.MIN_VALUE through Integer.MAX_VALUE. Arithmetic that produces a value outside this range can result in integer overflow.
  • Post-Increment and Post-Decrement: x++ and x-- add 1 or subtract 1 from the stored value of a numeric variable. Prefix forms such as ++x are outside the current AP CSA scope.

AP CSA 1.5–1.6: Casting & Compound Assignment

Question 1 of 15 | Score: 0
1. Consider the following code segment. What is printed as a result of executing the code segment?
double temperature = 88.9;
int displayTemp = (int) temperature;
System.out.println(displayTemp);
Correct Answer: C Casting a double to an int does not round the number mathematically; it explicitly truncates (chops off) the decimal portion entirely. Therefore, 88.9 simply becomes 88.
2. Consider the following code segment. What is printed?
double balance = -15.75;
System.out.println((int) balance);
Correct Answer: B Integer truncation removes the decimal portion. It always truncates toward zero, meaning -15.75 drops the .75 and becomes -15. It does not round down to the next lowest mathematical integer (-16).
3. Consider the following code segment. What gets printed?
int total = 11;
int count = 4;
double average = (double) (total / count);
System.out.println(average);
Correct Answer: B Because of the parentheses, the integer division (total / count) happens first. 11 / 4 evaluates to 2. After the integer division is entirely complete, that result (2) is cast to a double, turning it into 2.0. To get 2.75, the code would need to be (double) total / count;.
4. Consider the following code segment. What is printed?
int result = (int) ((double) 9 / 2);
System.out.println(result);
Correct Answer: A Follow the order of operations from the innermost parentheses outward:
1. (double) 9 casts the 9 to 9.0.
2. 9.0 / 2 performs floating-point division, yielding 4.5.
3. (int) 4.5 casts the result back to an integer, truncating the decimal, leaving exactly 4.
5. Consider the following code segment. What is printed?
int score = 50;
score += 15;
System.out.println(score);
Correct Answer: D The compound assignment operator += is a shorthand syntax. The statement score += 15; is functionally identical to score = score + 15;. Therefore, 50 + 15 evaluates to 65 and is assigned back to score.
6. Consider the following code segment. What gets printed?
int x = 10;
x *= 3 + 2;
System.out.println(x);
Correct Answer: B This is a notorious trap. Compound assignment operators treat the right side of the expression as if it were enclosed in parentheses. The statement x *= 3 + 2; actually evaluates as x = x * (3 + 2);. Therefore, it calculates 10 * 5, which equals 50.
7. Consider the following code segment. What gets printed?
int m = 23;
m %= 6;
System.out.println(m);
Correct Answer: B The statement m %= 6; translates to m = m % 6;. The modulo operator finds the remainder. 6 goes into 23 three times (18), leaving a remainder of 5.
8. Which of the following statements correctly rounds the positive double variable val to the nearest integer and stores it in roundedVal?
Correct Answer: C Because casting to an int truncates rather than rounds, adding 0.5 pushes values with a decimal of .5 or higher up to the next integer before truncation occurs. For example, if val is 3.6, 3.6 + 0.5 = 4.1. Truncating 4.1 yields 4.
9. Which of the following statements correctly rounds the negative double variable negVal to the nearest integer?
Correct Answer: B To round a negative double mathematically correctly, you must subtract 0.5 before casting to an int. For example, if negVal is -3.6, -3.6 - 0.5 = -4.1. Casting to an int truncates the decimal toward zero, yielding -4.
10. Assume int count = 10;. Which of the following is functionally equivalent to the statement count = count - 1;?
Correct Answer: B The decrement operator (--) subtracts 1 from the integer variable as a standalone statement. Option A assigns negative one (count = -1). Option D is a boolean comparison, not an assignment.
11. Consider the following sequential updates. What gets printed?
int val = 10;
val -= 3;
val *= 2;
System.out.println(val);
Correct Answer: B Variables maintain their updated states line by line in memory.
1. val -= 3; subtracts 3, updating val to 7.
2. val *= 2; multiplies the current value by 2, updating val to 14.
12. Which of the following lines of code will result in a compilation error?
Correct Answer: D The left side of an assignment operator must be a valid variable (an l-value). An expression like 2 += d attempts to reassign the value of the integer literal 2, which is impossible and immediately throws a compilation error. Note: Option C is legal because c =+ 5; evaluates to assigning a positive five: c = (+5);.
13. Assume int x1 = 5; and int x2 = 8;. Which of the following correctly stores the exact mathematical average (6.5) into the variable avg?
I. double avg = (x1 + x2) / 2;
II. double avg = (double) (x1 + x2) / 2;
III. double avg = (x1 + x2) / 2.0;
Correct Answer: D I is incorrect because (x1 + x2) / 2 divides an integer by an integer, resulting in 6, which is then implicitly widened to 6.0.
II is correct because the sum 13 is cast to 13.0 before division, triggering floating-point division.
III is correct because dividing by the floating-point literal 2.0 automatically promotes the sum 13 to 13.0, resulting in 6.5.
14. Consider the following code segment. What is printed?
int num = Integer.MAX_VALUE;
num++;
System.out.println(num);
Correct Answer: C Integer.MAX_VALUE is 2147483647, the largest value an int can store. The post-increment operator attempts to add 1, producing a value outside the int range. In Java, the resulting int value wraps around to -2147483648, which is Integer.MIN_VALUE.
15. Consider the following code segment. What is printed?
int p = 5;
int q = 3;
p += q * 2 + 1;
System.out.println(p);
Correct Answer: B Remember that p += [expression] equates to p = p + ([expression]). First, evaluate the entire right side using standard order of operations: q * 2 + 1 -> 3 * 2 + 1 -> 6 + 1 -> 7. Finally, add this result to the original value of p: 5 + 7 = 12.

Topics 1.5–1.6 Practice Complete!

0 / 15

Why Casting and Compound Assignment Matter for AP CSA

Casting and compound assignment are useful when tracing Java code because they can change both the type and value of an expression or update a variable in a compact statement. The current College Board framework includes casting, integer range, compound assignment operators, and post-increment and post-decrement operators in Unit 1.

Continue Your Unit 1 Practice

After practicing Topics 1.5–1.6, continue with the available Unit 1 practice assessment. The existing assessment covers selected Unit 1 foundation topics and is not a complete assessment of every current Unit 1 topic.

Continue your AP CSA review with the Unit 1 Foundation Mock Exam, featuring 20 mixed multiple-choice questions from the existing Unit 1 practice set.

← Previous Available: Topic 1.3 Expressions & Output
Next: Unit 1 Foundation Mock Exam →

Primary Sidebar

Mr Chinmay

Chinmay Patel
Book a Demo Class

Phone & Whatsapp +919853166385
javatution@gmail.com

Recent Posts

  • Learn Java in One Day: 10-Hour 1-on-1 Crash Course | JavaTutorOnline
  • Constructor in Java: Examples, Types & Constructor Overloading
  • Important Interview Questions on Java Multithreading
  • React Spring Boot Web Services React Integration
  • Spring Boot RESTful Web Services Example
  • Top Spring MVC Interview Questions and Answers for Developers
  • Top Spring Core Interview Questions and Answers for Developers
  • Host Java Web Apps for Free on Mobile with Tomcat and Termux
  • How to Deploy Java Web Application on Aws EC2 with Elastic IP
  • Simple Jsp Servlet Jdbc User Registration using Tomcat Mysql and Eclipse

Additional Resources

  • AP Computer Science A Summer Prep
Copyright © 2026 JavaTutorOnline