乘起来更高效
您的职位描述变了!现在每周的工作小时数和工作天数都更灵活。您可以基于之前编写的 squareOf5() 来轻松得到答案。
本练习是课程的一部分
Java 中级
练习说明
- 为
n1和n2指定合适的类型。 - 使用合适的运算符实现
n1和n2之间的乘法。 - 为
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");
}
}