+ 1
What is the output of the following code? Int x=3/2*4+3/8+3.
Pls define with steps.
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!
+ 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)
+ 1
3/2=1.5 and 1.5*4=6 and 6+3=9 and 9+3/8=? The answer written is 7 how???
+ 1
Ipang thanks man