hello, I’m facing an issue with this code
public class Main {
public static final int max_size = 5;
public static void main(String[] args) {
int sum = 0;
int above = 0;
int below =0;
//create an array of type double of size 15. to represent
//students marks in test 1.
double[] test1 = new double[max_size];
//Prompt the user to enter 15 marks and save them in the array
Scanner scan = new Scanner(System.in);
for (int i = 0; i< test1.length; i++) {
System.out.println("enter student " + i + " mark");
test1[i] = scan.nextDouble();
sum += test1[i];
}
//Calculate and output the average of all marks
double avg = sum / max_size;
System.out.println("avg: " + avg);
//Output the marks that are above the average.
for (int j = 1; j < test1.length; j++) {
if (test1[j] > avg) {
System.out.println("this mark " + test1[j] + " is above avg");
above++;
}
if (test1[j] < avg) {
System.out.println("this mark " + test1[j] + " is below avg");
below++;
}
}
System.out.println("number of marks above avg: "+above);
System.out.println("number of marks below avg: "+below);
}
}
the output:
enter student 0 mark
500
enter student 1 mark
100
enter student 2 mark
100
enter student 3 mark
100
enter student 4 mark
10
avg: 162.0
this mark 100.0 is below avg
this mark 100.0 is below avg
this mark 100.0 is below avg
this mark 10.0 is below avg
number of marks above avg: 0
number of marks below avg: 4
for some reason it did not count index 0 as an above avrage