Get percent of failing grades from an array
Hello everyone! I was working on a problem that I thought would be quite simple, but for some reason, my code won't return any percentage other than 0. I am supposed to return the percentage of grades that are less than 60 from an array of grades. This is what I came up with:
Code java:
public class FunctionalityTest
{
public float getPercentFailing(float[] grades)
{
int failed = 0;
for (int i = 0; i < grades.length; i++)
{
if (grades[i] < 60f)
{
failed += 1;
}
}
return failed / grades.length;
}
}
Any help or advice would be very much appreciated!
Re: Get percent of failing grades from an array
Integer arithmetic: 9/10 = 0
float arithmetic: 9.0/10 = 0.9
Make one of the numbers a float to get float arithmetic