Primitive Operators question 3 | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Primitive Operators question 3

What is the result of the following code? int x = 15; int y = 4; int result = x / y; System.out.println(result); R=3 //Is that real? I mean, I need to have x=12, for the (Result) R=3 //I try to do my best english guys.

1st Jun 2020, 11:32 PM
JOSUE FERNANDO PEREZ PINEDA
JOSUE FERNANDO PEREZ PINEDA - avatar
2 Réponses
+ 1
Both operands for division (<x> and <y>) and also <result> are integers, hence integer division operation be at work here. 15 / 4 => 3.75, but since integers do not support fraction, the 0.75 is discarded and results in just 3.
2nd Jun 2020, 1:03 AM
Ipang
0
For x= 12 and x =13 and x=14 and x=15 result is 3
1st Jun 2020, 11:40 PM
hossein sadeghi
hossein sadeghi - avatar