开始使用免费开始使用

乘起来更高效

您的职位描述变了!现在每周的工作小时数和工作天数都更灵活。您可以基于之前编写的 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");
  }
}
编辑并运行代码