開始使用免費開始

平方

你每天工讀 5 小時、每週 5 天,經常需要用到 5 的平方。與其在程式碼各處重複,不如寫一個方法來讓這件事更方便。

本練習屬於課程

Java 中級

檢視課程

練習說明

  • 為自訂方法的 return 指定正確的 type
  • 呼叫該方法,並將結果儲存為 hours

動手互動練習

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

class Squarer {
  // Give this function the proper return type
  static ____ squareOf5() {
    return 5 * 5;
  }

  public static void main(String[] args) {
    // Call the correct function name defined above
    int hours = ____();
    System.out.println("I'm working " + hours + " hours a week");
  }
}
編輯並執行程式碼