What is the output of the following code? Int x=3/2*4+3/8+3. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the output of the following code? Int x=3/2*4+3/8+3.

Pls define with steps.

18th Sep 2021, 4:58 AM
King
King - avatar
4 Answers
+ 6
3 / 2 yields 1.5 But because both operands are integer, fractional is ignored and thus it ended up being 1 Then multiply that result (1) with next number (4), and you get 4 Next, you see 3 / 8 which yields 0.375. But again, because both operands are integer, fractional is ignored, and you only get 0. This has no effect as 4 + 0 is just 4 (duh) Finally, add the last number (3). You got it!
18th Sep 2021, 5:57 AM
Ipang
+ 3
3/2 = 1.5 because it's (int) so = 1 ; 3/8 = 0.375 because it's (int) so = 0 ; then the question will be like this 1*4 + 0 + 3 = 7 So it's (7)
19th Sep 2021, 9:01 PM
Hamza Hussein
Hamza Hussein - avatar
+ 1
3/2=1.5 and 1.5*4=6 and 6+3=9 and 9+3/8=? The answer written is 7 how???
18th Sep 2021, 5:56 AM
King
King - avatar
+ 1
Ipang thanks man
18th Sep 2021, 6:02 AM
King
King - avatar