Write a method that takes an int array of marks and returns how many are 50 or above. Then write a second method that returns the average as a double. Call both from main with the marks 40, 70, and 90.
When that runs, the count is 2 and the average is 66.666... with a double division. After that, store the same marks in an ArrayList and print only the passing ones.
Example
The loop visits three marks. Only two satisfy mark >= 50, so the method returns 2.
public class Practice {
static int passing(int[] marks) {
int count = 0;
for (int mark : marks) {
if (mark >= 50) count = count + 1;
}
return count;
}
public static void main(String[] args) {
int[] marks = {40, 70, 90};
System.out.println(passing(marks));
}
}