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

15. Given the variable declaration/initialization statements shown below, evalua

ID: 3594784 • Letter: 1

Question

15. Given the variable declaration/initialization statements shown below, evaluate i after executing each java code fragment. Be sure to show your work. If you don't I cannot give you partial credit for the portion of the work you got right. Assume: int a = 1, b = 2, c-3; a. int i=(a+b+c)*((a + b) 96 c); b. int i = (a + b + c) / Math.sqrt(c + a) + (a-c); c, boolean i = 5"b % 3 > b / c % 2; d. int 0; boolean lucky = true; if (!lucky)(i = 7;} else {-13;} int i; int lucky =-1; switch (lucky * lucky){ case 1: i0; break;) e. 7; break; case 0: i-13; break; default: f, int i = 5; while (i > 4)(ii-3;} g, int i; for(int j = 2; j

Explanation / Answer

As per Chegg policy, I am answering only first 4 subparts:

a.) i = (1+2+3)* ((1+2)%3) = (6 * (3%3)) = 6*0 = 0

b.) If we try to execute the fiven statement, it will give error: possible loss of precision from double to int. But if you declare i as double then we will have

i = (1+2+3)/ Math.sqrt(3+1) + (1-3) = 6/2.0 + (-2) = 3.0 - 2 = 1.0

c.) i = 5*2%3>2/3%2 = 10%3>2/3%2 = 1>2/3%2 = 1>0%2 = 1>0 = true

d.) Since lucky == true. Therefore, condition in if block evaluates to false and statements in else will execute which gives i = 13.

Hope it helps, do give your valuable response.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote