Test how Java converts values, handles numeric limits, and updates variables.
Run the code and explain what changed.
1. Run the program exactly as shown.
2. Describe what happened when each double became an int.
3. Compare automatic widening with the explicit (double) cast.
4. Explain why narrowing can lose data while widening does not.
Push an int past the edge and explain the result.
1. Run the code exactly as shown.
2. Observe what happens after the largest int increases by one.
3. Explain why subtracting one from the smallest int produces another in-range value instead of an error.
Run the decimals and explain the strange output.
1. Run the program exactly as written.
2. Compare the printed values with the decimal results you expected.
3. Explain why double calculations can contain small round-off errors.
Compare truncation with rounding for the same positive value.
1. Cast measurement directly to int and store the result.
2. Round the same positive value by adding 0.5 before casting.
3. Print the original value and both integer results.
4. Explain why casting and rounding produce different answers.
Replace the long updates without changing the result.
1. Rewrite the same program with compound assignment operators.
2. Use ++ where it naturally fits.
3. Keep the starting value and final printed result exactly the same.
Compare casting before division and after division.
1. Run the code and compare the two printed values.
2. Decide which line casts before the division happens.
3. Explain why one result becomes 0.0 while the other remains 0.4.
Predict the result before you run it.
1. Predict the final printed value before you run the program.
2. Run the program and check whether your prediction was correct.
3. Translate each shortcut line back into long form to explain the result.
Change the program so it reaches the right output.
1. Run the program and compare its result with the target output.
2. Change the code so it matches the target exactly.
3. Keep the structure simple and use only the shortcut operators from this lesson.
1248
Decide what must be true before two ints are added.
1. Run the expression and observe the unexpected result.
2. Choose two replacement int values that can be added safely.
3. Describe what must be true about the sum before the addition happens.
4. Explain why two valid int values can still produce overflow.
Compare two similar lines and explain why they differ.
1. Run both lines and compare the printed values.
2. Decide which expression casts first and which expression adds first.
3. Explain how the parentheses changed the meaning of the code.
Work backward from two target values.
1. Start with the value shown.
2. Use one compound assignment operator to change val to 25, then print it.
3. Use ++ to change val to 26, then print it.
4. Match the target output without spaces or a line break between the two values.
2526
Repair an average that loses its decimal part.
1. Run the program and decide whether the printed average is mathematically correct.
2. Fix the code so the average keeps its decimal value.
3. Explain why the original line lost information before the result reached the double variable.
Round both positive and negative values instead of truncating.
1. Create one expression that rounds positiveDistance to the nearest int.
2. Create another expression that correctly rounds negativeDistance.
3. Store both rounded results in integer variables.
4. Print each original value beside its rounded result.
Trace a short chain of increment and decrement updates.
1. Predict the final printed value before you run the code.
2. Run the program and check your prediction.
3. Explain the value after each update in order.