Evaluating Expressions that Contain Nested Loops
Need Help? Check out these resources!
Evaluating Expressions
|
Grab a Piece of Paper! |
Evaluate each expression. Verify your answer by running the code in the Java Playground. |
Practice 1: Order IDs: years 2019-2021, order 1-5
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
- If the loop concludes, what is the value of
numwhen the loop is completed? - If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
- If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?
Practice 2: Combination lock: 2 dials (0 - 9)
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
- If the loop concludes, what are the values of
dial,dial2, andcodefoundwhen the loop is completed? - If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
- If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?
Practice 3: Sports matches: 4 teams, 1 rounds
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
- If the loop concludes, what is the value of
pagewhen the loop is completed? - If the code results in an infinite loop, explain why. How would you modify the code so that it is no longer an infinite loop? Make this change.
- If the code causes the loop to not execute at all, explain why. How would you modify the code so that the loop iterates at least 1 time?