QUESTION IMAGE
Question
consider the following:
int a = 15;
int b = 5;
int c = 3;
system.out.println(a + 25 / b);
system.out.println(c - 31 / a);
what is the output of this program?
20 1
8.933333
8 1
Step1: Calculate first print statement
According to operator precedence, division is done before addition.
For a + 25 / b, substitute \(a = 15\), \(b = 5\). First calculate \(25\div5=5\), then \(15 + 5=20\).
Step2: Calculate second print statement
For c-31/a, substitute \(c = 3\), \(a = 15\). First calculate \(31\div15\). In Java, when two int values are divided, the result is an int (truncated towards zero). \(31\div15 = 2\) (since \(15\times2=30\) and \(31 - 30=1\), the remainder is discarded as it's int division). Then \(3-2 = 1\).
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
20 1