Answer:
In Java:
The method is as follows:
public static int countInRange (ArrayList<Integer> MyList, int min, int max) {
int count = 0;
for (int i = 0; i < MyList.size(); i++) {
if(MyList.get(i)>=min && MyList.get(i)<=max){
count++;
}
}
return count;
}
Explanation:
This defines the method
public static int countInRange (ArrayList<Integer> MyList, int min, int max) {
This declares and initializes count to 0
int count = 0;
This iterates through the ArrayList
for (int i = 0; i < MyList.size(); i++) {
This checks if current ArrayList element is between min and max (inclusive)
if(MyList.get(i)>=min && MyList.get(i)<=max){
If yes, increase count by 1
count++;
}
}
This returns count
return count;
}
To call the method from main, use:
countInRange(v,m,n)
<em>Where v is the name of the ArrayList, m and n are the min and max respectively.</em>