- 2
What Is The answer of This one
What is the result of the following code? int x = 15; int y = 4; int result = x / y; System.out.println(result);
12 Answers
+ 4
@Ulisses Cruz
Yes, I was explaining how it works.
+ 4
Answer is 3 because you are using 'int' data type which means you are dividing whole numbers(numbers without decimal places) and your answer will also be a whole number. So the numbers after decimal will be ignored in this case, so answer would be 3.
+ 3
3.
Wouldn't have running that code been better than asking us?
+ 3
With integer division everything past the decimal is truncated.
15/4 = 3.75
The .75 is cut off leaving 3 as the answer.
0
3
0
0
15/6
Table 6*2=12
(15-12)=3
3 is remainder
0
15/4
Table 4*3=12
(15-12)=3
3 remainder
0
3
0
+3
0
Translate course
What is the result of the following code?
int x = 15; int y = 4;
int result = x / y;
System.out.println(result);
Answer is 3
0
int x = 8, y = 5;
int result = x % y;
Answer is 3