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

import java.util.Scanner; // Outputs max of list of integers //First value indic

ID: 3735524 • Letter: I

Question

import java.util.Scanner; // Outputs max of list of integers //First value indicates list size // Ex: 4-1 9 3 yields 9 public class ListMax public static void main(String [ args) ( Scanner scnr new Scanner (System.in); int maxSoFar 0; int currValue; int numValues; int i; numValues scnr.nextInt (); for (i 0;inumValues; ++i) currValue scnr.nextInt): if (í == ) { // First iteration maxSoFarcurrValue; else if (currValue > maxSoFar) maxSoFar-currValue; if (numValues >0) { System . out, println("Max: " +maxSoFar);

Explanation / Answer

Ques 1. Answer : 0

The value of maxSoFar = 0

Ques 2. Answer : 4

As i = 0, so the if block is executed. So, maxSoFar is set to 4.

Ques 3. Answer : 4

As i != 0, so the if block is not executed. Also, the else block is not executed as -1 < 4.

Ques 4. Answer : 9

As i != 0, so the if block is not executed. The else block is executed as 9 > 4. So, the value of maxSoFar is set to 9.

Ques 5. Answer : 9

As i != 0, so the if block is not executed. Also, the else block is not executed as 0 < 9.

Ques 5. Answer : 9

As i != 0, so the if block is not executed. Also, the else block is not executed as 3 < 9.