THe following main method should print on out put thje total and average of all
ID: 3918345 • Letter: T
Question
THe following main method should print on out put thje total and average of all numbers in the int[] numbers array. Please complete the coding parts of both the getSum and getavg methods. You must use for or while loop statements for both methods.
G File: Practice.java CAUsers) W2103619521 Documents -jGRASP CSD (Java) File Edit View Bi Project Settings Tools Window Help All Fil? | So |? ublic class Practice public static void main (String [] args) C1UsersWV210| ? int [ ] numbers { 10, 40, 15, 20, 25, 30, 35, 5); double sum 0, Average=0; sum-getSum (numbers) Average=getavg (numbers) ; System.out.printin(" The Total"+sum; System .out.printIn(" The Average "+ Average); Practice.java public static int getsum (int Array]) int sum=0; //write code here return (sum) public static double getavg (int Array[]) int sum-0 //write code here return (sum/ Array.length) Practice.java Compile Messages jGRASP Messages Run IOInteractions Stop Clear Browse Find Debug Workbench Line:1 Col:22 Code:0 Top:1Explanation / Answer
Practice.java
public class Practice {
public static void main(String[] args) {
int[] numbers = {10,40,15,20,25,30,35,5};
double sum=0, Average =0;
sum = getSum(numbers);
Average = getavg(numbers);
System.out.println("The Total: "+sum);
System.out.println("The Average: "+Average);
}
public static int getSum(int Array[]){
int sum = 0;
for(int i=0;i<Array.length;i++) {
sum+=Array[i];
}
return sum;
}
public static double getavg(int Array[]){
int sum = 0;
sum = getSum(Array);
return sum/(double)Array.length;
}
}
Output:
The Total: 180.0
The Average: 22.5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.