Bắt đầu ngayBắt đầu miễn phí

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 dice's result. A critical hit happens when the die shows 20.

Bài tập này là một phần của khóa học

Intermediate Java

Xem khóa học

Hướng dẫn bài tập

  • 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.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

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

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

    // Check if result is lower or equal to ten
    if (____ <= ____) {
      System.out.println("Unfortunately, you miss");
    }
  }
}
Chỉnh sửa và Chạy Mã