開始使用免費開始

乘起來更給力

你的職務內容改變了!現在每週的工時與工作天數更有彈性。你知道可以沿用先前做的 squareOf5(),就能更快得出答案。

本練習屬於課程

Java 中級

檢視課程

練習說明

  • n1n2 指定正確的型別。
  • 使用正確的運算子來計算 n1n2 的乘積。
  • hours 使用正確的型別來承接 mult()return 值。

動手互動練習

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

class Multiplier {
  // Give these arguments the proper type
  static int mult(____ n1, ____ n2) {
    // Use the appropriate operator to get the multiplication of 2 numbers
    return n1 ____ n2;
  }

  public static void main(String[] args) {
    int n = 5, m = 6;
    // Give the correct type to hours to retrieve the return value of mult
    ____ hours = mult(n, m);
    System.out.println("I'm working " + hours + " hours a week");
  }
}
編輯並執行程式碼