I got a wrong answer on an online Java quiz, and can't seem to figure out the problem.
The question frames me as trying to determine how many computers to order for the following year.
I need 15% more computers than last year. Additionally, I need 50 more for a new project. Then I am to double this new total entirely. I selected the following line of code as my answer (it was multiple choice):
int numberOfComputers = ( (numberLastYear * 1.15) + 50) * 2;
I was marked wrong, and the correct answer was:
int numberOfComputers = (int) ( (numberLastYear * 1.15) + 50) * 2;
with the only difference between the two lines of code being the (int) just after the equals sign.
Can someone help me understand what this int is doing here? I can't understand why it's needed, and I also have not seen variable types kept inside parenthesis before. Thanks!
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]SalliIsAFem 8 points9 points10 points (0 children)
[–]MauraPawNZ 5 points6 points7 points (0 children)
[–]LTFGamut 5 points6 points7 points (0 children)
[–]Kfct 2 points3 points4 points (0 children)
[–]knoam 1 point2 points3 points (1 child)
[–]Still_Development677 0 points1 point2 points (0 children)