Skip Top Navigation Bar

Evaluating Expressions that Contain if Statements

Evaluating Expressions

Grab a Piece of Paper!

Evaluate each expression.

Verify your answer by running the code in the Java Playground.

Practice 1: Shopping Cart Discount

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for totalPurchase and corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 2: Bank Account Withdrawal

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for balance and withdrawal as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 3: Temperature Check

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for temperature as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 4: Library Membership Verification

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for hasLibraryCard and hasPhotoID as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 5: Library Membership Verification

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for age and parentalConsent as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 6: Vacation Approval

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for isManager and daysAvailable as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 7: Contest Participation

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for age and hasParentPermission as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 8: Multi-level Discount Application

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for totalPurchase and isMember as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 9: Exam Result Status

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for score and attendedExam as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Practice 10: Delivery Zone and Availability Check

  • Predict the output of the expression.
  • Verify your prediction is correct by running the code in the Java Playground.
  • Identify possible values for city and slotsAvailable as well as the corresponding outputs that can be used to test the code is working as expected.
  • Modify the code to use these test values.
  • Verify the corresponding outputs by running the code in the Java Playground.

Resources