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

Suppose that the input is: 38 45 71 4 -1 What is the output of the following cod

ID: 3608286 • Letter: S

Question

Suppose that the input is: 38   45   71  4   -1 What is the output of the following code (Assume allvariables are properly declared): sum = console.nextInt(); num = console.nextInt(); while (num ! = -1) {    sum = sum + num;    num =console.nextInt(); } System.out.println("Sum = " + sum); Please explain how you arrive at thissolution Suppose that the input is: 38   45   71  4   -1 What is the output of the following code (Assume allvariables are properly declared): sum = console.nextInt(); num = console.nextInt(); while (num ! = -1) {    sum = sum + num;    num =console.nextInt(); } System.out.println("Sum = " + sum); Please explain how you arrive at thissolution {    sum = sum + num;    num =console.nextInt(); } System.out.println("Sum = " + sum); Please explain how you arrive at thissolution

Explanation / Answer



It is 158.

Reason:
intialy sum =38 num =45
now in loop it sum to numuntil num is -1. so it willexecute
Iteration1 num = 45 and sum= sum +num = 38 + 45 = 83 Num has changed to71
Iteration2 num = 71 and sum= sum +num = 83 + 71 = 154 Num has changed to4
Iteration3 num = 4 and sum= sum +num = 154 + 4 = 158 Num has changed to-1
Iteration1 num = 45 and sum= sum +num = 38 + 45 = 83 Num has changed to71
Iteration2 num = 71 and sum= sum +num = 83 + 71 = 154 Num has changed to4
Iteration3 num = 4 and sum= sum +num = 154 + 4 = 158 Num has changed to-1
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