java - bus company using only arithmetics -
my homework assignment is: run bus company , need know how many buses need used, based on number of seats in bus , number of passengers. example: if have 17 passengers , 3 seat bus, have use 6 buses. 5 buses first 15 people , 1 2 remaining.
i cant use loops, if statements, or recursion, arithmetic.
this pseudo code it's wrong:
numbus=numofpeople / seat; remain=numofpeople % seat; temp=numofbus % remain; orderbus=numbus+temp; system.out.println(orderbus);
since given strict requirement on no loops , ifs, can't use ternary operator well. in fact, don't need those.
it can simple as:
system.out.println(math.ceil(passengers/seat));
for example (math.ceil(17/3.0));
gives 6.0
. need quotient dividing passengers seats. if quotient not whole number, round one. achieved using math.ceil()
.
so if there remainders, round 1 (1 more bus ferry rest of passengers)
Comments
Post a Comment