開始使用免費開始

成績評定

在你的學校,學生會在線上查詢成績。你想確保當分數「嚴格」高於 11 時,學生會收到讚美,同時在不及格時也能收到清楚的訊息。成績範圍是 0 到 20,10 為及格分數。

本練習屬於課程

Java 中級

檢視課程

練習說明

  • 使用正確的運算子與數字,確保 grade「嚴格」大於 11 時會給出讚美。
  • 使用正確的關鍵字,確保只有在前一個條件為假且符合另一個條件時才會進入。
  • 使用適當的關鍵字來涵蓋所有其他情況。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

class Grader {
  public static void main(String[] args) {
    int grade = 14;

    // Check if the grade is above 11
    if (grade ____ ____) {
      System.out.println("You've outdone yourself");
      // If the above condition is not met, check if the grade is at least 10
    } ____ ____ (grade >= 10) {
      System.out.println("You get a passing grade");
      // Add the correct keyword to grab every other possible case
    } ____ {
      System.out.println("You get a failing grade");
    }
  }
}
編輯並執行程式碼