+ 1

Help with this method

Can someone help debug the code below as a solution to this problem?: The program takes scores as input. The method should take the inputs as parameters, and then calculate and return the average score. Sample Input 6.0 4.0 5.0 3.0 Sample Output 4.5 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); double score1 = read.nextDouble(); double score2 = read.nextDouble(); double score3 = read.nextDouble(); double score4 = read.nextDouble(); double avgScore = getAverageScore(score1, score2, score3, score4); System.out.println(avgScore); } //what is wrong with this method? public static double getAverageScore(double score1, double score2, double score3, double score 4) { double avgScore = (score1 + score2 + score3 + score4)/4; return (double avgScore); } }

2nd Jan 2021, 2:02 PM
Tommy Mensah
2 Answers
0
Tommy Mensah Why are you returning `double avgScore`? What's the point of the `double` type specifier there? That is the first problem. The second problem is that you have space between `score` and `4` in the argument list in the declaration of the `getAverageScore` method. It should be `double score4`, but it is `double score 4`
2nd Jan 2021, 2:09 PM
XXX
XXX - avatar
0
Thank you XXX
2nd Jan 2021, 2:47 PM
Tommy Mensah