answersLogoWhite

0

public int sum(int[] x) {
int sum = 0;
for(int i : x) {
sum += i;
}
return sum;
}

public int average(int[] x) {
// Note that this returns an int, truncating any decimal
return sum(x) / x.length;
}

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor

Add your answer:

Earn +20 pts
Q: Create a program that compute the sum and average of 20-elements array x?
Write your answer...
Submit
Still have questions?
magnify glass
imp