Evaluating Expressions
|
Grab a Piece of Paper! |
Evaluate each expression.
Verify your answer by running the code in the Java Playground.
|
Practice 1: Theater Seats
- 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
seat when 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: Time Counts Down
- 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
minutes when 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: Printing Pages
- 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
page when 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 4: Next Customer
- 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
customer when 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 5: Hours Left
- 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
hoursLeft when 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 6: To Task
- 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
id when 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?
Resources
Practice: Write Expressions that Contain for Loops