開始使用免費開始

批次檢查

你負責不同批次巧克力盒的品質檢查。你知道有其中一批過重,但不確定是哪一批。請依序列印出各批的重量,找出哪一批超過 220g。

本練習屬於課程

Java 中級

檢視課程

練習說明

  • 使用正確的符號來標示元素與集合之間的區隔。
  • 呼叫正確的變數,印出每一批的重量。

動手互動練習

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

class WeightWatcher {
  public static void main(String[] args) {
    int[] weights = {198, 190, 188, 187, 190, 198, 201, 250, 203, 210, 205, 170, 180, 200, 203, 210, 180};

    // Use the correct symbol to mark the difference between the elements and the collection
    for (int weight ____ weights){
      // Call the right variable to print how much each batch weighs
      System.out.println(____);
    }
  }
}
編輯並執行程式碼