I'm struggling to learn arrays in Java. I have some code which includes an array of Integer for attendance over 10 weeks with a class size of 15. The task is to output the percentage attendance for each week. I've managed to create a for loop to access each value in the array and I have done what I think is correct to cast these to double so that I can work out the percent of each. I encounter issues when trying to output results. Firstly when trying to println the error is that i has not been initialised. I have i in my for loop and if i take it out of the for loop i get output of 8.0 which is not what I want. Secondly, I would like all results to be numbered 1 to 10 but again the +i+ in println is not working for me and I don't know why. Could someone tell me what I have done wrong with i? Thanks
public class AttendanceTest {
public static void main(String[] args) {
final Integer CLASS_SIZE = 15;
Integer[] attendances = {10, 14, 12, 9, 11, 15, 12, 13, 8, 14};
double attendance=0;
{for(int i=0;i<attendances[i];i++)
attendance=(double) (attendances[i] / 15)*100;
System.out.println(+i+attendance );
}
}
}