乘起來更給力
你的職務內容改變了!現在每週的工時與工作天數更有彈性。你知道可以沿用先前做的 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");
}
}