APCSA Practice: What Does This Java Method Return for an Array? 💻

preview_player
Показать описание
📢 What is the output of the mystery method when passed the array {10, 30, 30, 60}?

java
Copy
public static double mystery(int[] arr) {
double output = 0;
output = output + arr[i];
}
}
Options:
A) 17.5
B) 30.0
C) 130
D) 32
E) 32.5

📝 Solution Breakdown:
1️⃣ The array passed to the mystery method is {10, 30, 30, 60}.
2️⃣ The method calculates the sum of the elements:
10 + 30 + 30 + 60 = 130.
3️⃣ The method then divides the sum by the length of the array, which is 4:
130 / 4 = 32.5.
🔥 Final Answer: Option E — 32.5
🔑 Key Takeaway:
The method returns the average of the elements in the array.

#Java #ArrayMethod #AverageCalculation #JavaCoding #LearnJava #Programming #APCSA
Рекомендации по теме
visit shbcf.ru