casting · overflow · round-off · shortcuts
Run the code and explain what changed.
1. Run the program exactly as shown.
2. Describe what happened after each double became an int.
3. Explain why the decimal part disappeared in both cases.
Push an int past the edge and explain the result.
1. Run the code exactly as shown.
2. Observe what happened after the largest int increased by one.
3. Explain why the smallest int can still keep going instead of stopping with an error.
Run the decimals and explain the strange output.
1. Run the program exactly as written.
2. Compare the printed values to the decimal math you expected in your head.
3. Explain why double calculations can still look slightly off.
Convert a decimal amount into cents safely.
1. Create a program that starts with the amount shown.
2. Convert that amount into cents and store it in an int.
3. Add a rounding step before the cast so the cents value stays accurate.
4. Print the original amount and the final cents value.
Replace the long updates without changing the result.
1. Rewrite the same program with shortcut 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 keeps the decimal part.
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 output to 1248.
2. Change the code so it actually prints 1248 in order.
3. Keep the structure simple and stay inside the shortcut-operator ideas from this lesson.
Decide what must be true before two ints are added.
1. Read a method that adds two int values and prints the sum.
2. Describe what must already be true so the addition does not overflow.
3. Explain why knowing each number is an int is not enough by itself.
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.
Finish a checkout calculation without losing cents.
1. Create a final total by combining the subtotal and the tax rate.
2. Convert that final total into cents with an accurate rounding step.
3. Print the total in dollars and the final cents value.
Write a tiny shortcut-operator program from a target result.
1. Create a short program that starts from the value shown.
2. Use shortcut operators so the output becomes 2526.
3. Print the two numbers back to back in the correct order.
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.
Turn a decimal into the nearest int instead of truncating.
1. Create an expression that rounds the value shown to the nearest int.
2. Store the rounded result in an integer variable.
3. Print both the original decimal and the rounded integer.
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.