Consider the following code segment. What is the value of x after execution of the code? double [] numList = {4.17, 3.11, 2.46, 1.57}; int x = 0; for(double n : numList) { x += (int)n * 2; }
@Ultrilliam
I put 23
for future reference: ```c double [] numList = {4.17, 3.11, 2.46, 1.57}; int x = 0; for(double n : numList) { x += (int)n * 2; } ``` \```language code here \``` But anyway, taking this step by step: Go through each number, multiply it by 2, and add it all together, then you have x
and remove anything past the decimal from each*
so 4.17*2=8, rather than 8.34
ok sooo its 20 then
I get 21 actually
But its 8+6+4+2
8 and 2 is 10 then you jsut add the 6 for 16 and then the 4 to get 20
The last one is 3,
But i thought we removed anything past the decimal
And 21 isnt an option
Ah, I was doing it after it multiplied, my bad, lol
So it is 20?
Ok sweet I got a couple more can you help me with those i feel like im kidna getting it but they are all a bit different
Sure
Join our real-time social learning platform and learn together with your friends!