0

Hey Hi In this code why result is 3 Can you explain somebody

int x=15; int=4; int result=x/y system.out.println (result); why is 3

8th Dec 2016, 1:57 PM
iozandmixro
iozandmixro - avatar
4 Answers
+ 1
listen if you want 3.25, then do this float result = x/y
9th Dec 2016, 1:22 PM
Rishi Anand
Rishi Anand - avatar
+ 1
It's not a matter of rounding up or down when it comes to integer devision, more so the 'extra decimals' are just cut off. The answer is 3.25, however as int was used, the answer is simply 3.
13th Dec 2016, 3:45 PM
Jason Kumar
Jason Kumar - avatar
0
That is because your result is integer variable. So when you divide 15 by 4, the answer 3.25 is converted into integer 3 by dropping its decimal part
8th Dec 2016, 2:17 PM
Rishi Anand
Rishi Anand - avatar
0
this mean that do become 15;4=results or not...
9th Dec 2016, 12:00 PM
iozandmixro
iozandmixro - avatar