class Solution {
public static int vacationRental(int people, int day) {
// Please complete the function
if(day<=3) int perDay=80;
else if (4<=day&day<=9) int perDay=60;
else int perDay = 50;
return Math.floor(people*perDay*day*1.12);
}
}
The variable perDay
must be declared only once before it can be used.
Therefore, declare intperDay
at the beginning of the class and use it only in each if
, else
section.
class Solution {
public static int vacationRental(int people, int day) {
// Please complete the function
int perDay;
if(day<=3)perDay=80;
else if (4<=day&&day<=9)perDay=60;
else perDay = 50;
return(int) Math.floor(people*perDay*day*1.12);
}
}
I think so.
© 2024 OneMinuteCode. All rights reserved.