Get startedGet started for free

Dice game

You are hoping to develop a video game based on dice throwing. To that end, you want to implement a workflow that is going to give different outputs depending on the die's result. A critical hit happens when the die shows 20.

This exercise is part of the course

Intermediate Java

View Course

Exercise instructions

  • Use the correct operator to make sure that the result is 20 before printing.
  • Surround the operator in the right way to print only if the result is lower or equal to 10.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

class DiceGame {
  public static void main(String[] args) {
    int result = 20;

    // Use the correct operator to make sure it's a critical hit
    if (result ____ 20) {
      System.out.println("That's a critical hit!");
    }

    // Enter the correct value and variable to make it miss below 10
    if (____ <= ____) {
      System.out.println("Unfortunately, you miss");
    }
  }
}
Edit and Run Code