A Java program that is supposed to compute the average of an array of numbers in
ID: 3805556 • Letter: A
Question
A Java program that is supposed to compute the average of an array of numbers instead computes the sum of the numbers. This is an example of what kind of error: a. Runtime error b. Syntax error c. Logical error d. Array error 2. What will be printed by the println statement at the end of this code segment? int [] arr = (2, 4, 6, 8); int i = arr length-1: while (i >0)(String msg = "Value: +"arr [i];i = i = 1;} System.out.println (msg); a. "Value: 2" b. "Value: 4" c, "Value: 6" d. "Value: 8" e. None of the above-the above segment has an error in it. In the space below give a explanation of what the error is: 3. Consider the method header public static int enigma {double d. string s Which of the following could be a correct method call? a. int enigma (d, s) s) b. enigma (double d, String s). c. I = enigma (d, s) d. int enigma (double d, String s)Explanation / Answer
1. Answer : C - Logical Error
2. Answer : B - Value : 4 since the print statement is out of while loop and i>0 refers i=1 where loop exits and msg variable is assigned last with arr[1] which is 4
3 .Answer : C - i = engima(d,s) - this is the correct answer since we have int which is returned to function and i is the integer type
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.