Input an int array and returns the average of the numbers in it.
public class Average {
public static int averageFinder(int[] arr) {
int total = 0;
for(int num: arr){
total += num;
}
int result = total / arr.length;
return result;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
Average av = new Average();
int arr1[] = {96, 98};
assertEquals(97, av.averageFinder(arr1));
int arr2[] = {94, 96, 98};
assertEquals(96, av.averageFinder(arr2));
}
}