Evaluating Expressions
|
Grab a Piece of Paper! |
Evaluate each expression.
Verify your answer by running the code in the Java Playground.
|
Practice 1: Counting Loop
- 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
i
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: Saying Hello
- 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
count
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: Counting
- 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
count
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: Summing
- 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
count
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: Skip Counting
- 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
count
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: By Tens
- 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
val
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 7: Multiplying
- 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
num
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 do..while Loops