I am fairly new to Java coding.I have an exercise that demands to calculate an average of marks according to registration for modules.I checked the code so many times,but I can't find where Is the error.This Is what I do:
public class Student {
double mark1, mark2, mark3, mark4, mark5, mark6;
boolean regModule1, regModule2, regModule3, regModule4, regModule5, regModule6;
boolean tabModule[] = {regModule1, regModule2, regModule3, regModule4, regModule5, regModule6};
double tabmark[] = {mark1, mark2, mark3, mark4, mark5, mark6};
public void average() {
double sum = 0;
int count = 0;
double av;
for(int i=0; i<=5; i++) {
if(tabModule[i] == true) {
count++;
sum += this.tabmark[i];
}
}
av = sum/count;
System.out.println("the average is: " + av);
}
}
That's the code in the main:
e1.regModule1 = true;
e1.regModule4 = true;
e1.mark1 = 18.5;
e1.mark4 = 13.25;
e1.average();
When I run the project, I receive this:
the average is: NaN(not a number)
what I'm messing here?