Ask your own question, for FREE!
Computer Science 67 Online
SourMunchkin7806:

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; }

SourMunchkin7806:

@Ultrilliam

SourMunchkin7806:

I put 23

Ultrilliam:

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

Ultrilliam:

and remove anything past the decimal from each*

Ultrilliam:

so 4.17*2=8, rather than 8.34

SourMunchkin7806:

ok sooo its 20 then

Ultrilliam:

I get 21 actually

SourMunchkin7806:

But its 8+6+4+2

SourMunchkin7806:

8 and 2 is 10 then you jsut add the 6 for 16 and then the 4 to get 20

Ultrilliam:

The last one is 3,

1 attachment
SourMunchkin7806:

But i thought we removed anything past the decimal

SourMunchkin7806:

And 21 isnt an option

Ultrilliam:

Ah, I was doing it after it multiplied, my bad, lol

SourMunchkin7806:

So it is 20?

Ultrilliam:

1548178611-5c4754b3717a1cee3213a8-image.png

SourMunchkin7806:

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

Ultrilliam:

Sure

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
luvnickk: what typa music yall listen to ?
17 minutes ago 10 Replies 2 Medals
GothgirlLillian: Is music considered art?
39 minutes ago 1 Reply 0 Medals
luvnickk: am newwww
2 hours ago 0 Replies 0 Medals
russianmafiya: can someone help me write a love song
3 hours ago 1 Reply 0 Medals
velmalovesshaggy145: Isnu00b4t this the opening melody to mood by 24kgoldn feat iann dior? https://voca.
41 minutes ago 8 Replies 2 Medals
arrivhn: ADD ME ON DISCORD ICYAFFL
3 hours ago 4 Replies 1 Medal
arrivhn: whats is the accute of a cricle
3 hours ago 4 Replies 3 Medals
arrivhn: KNOCK KNOCK
3 hours ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!