Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For each question, I provided the answer. Can you please describe the way to arr

ID: 3909762 • Letter: F

Question

For each question, I provided the answer. Can you please describe the way to arrive at the answers?

a) Assume int x=3;

(x/10) evaluates to: __________ (answer = 0)

(x/2.0) evaluates to: __________ (answer = 1.5)

(x + 5 * 4 + 3 / 2) evaluates to: __________  (answer = 24)

b) Assume boolean b1 = true, b2 = false; int i = 100, j = -4;

b1 || (j>0) || (b2 && i==100) evaluates to: __________ (answer = true)

Can you also describe why the || in this problem is considered to have short circuted?

b1 && (b2 || i>j) && (b1 != b2) evaluates to: __________ (answer = true)

(b2 || !b2) evaluates to: __________ (answer = true)

Explanation / Answer

a.)

int x=3;

x/10 = 0 because numerator x(i.e 3) is integer and denominator(i.e 10) is also an integer. Therefore output will be integer. (In programming int/int=int).

-------------------------------------------------------------------------------------------------------------------------

x/2.0=1.5 because its denominator (i.e 2.0) is a float value and if float value comes in either numerator or denominator , it gives output in FLOAT. (i.e int/float=float or float/int= float or float/float=flaot)

---------------------------------------------------------------------------------------------------------------------------   

(x+5*4+3/2) = 24. The output comes 24 because of precedence of operator and its associativity. First 5*4 will operate and gives 20, then 3/2 will operate because of associativity(left to right). It gives 1 (int / int =int). After that addition will perform .

3+5*4+3/2

=3+20+3/2

=3+20+1

=23+1

=24

Ans.