Answer: provided in explanation segment
Explanation:
the code to carry out this program is thus;
import java.util.ArrayList;
import java.util.Scanner;
public class ArrayListMode {
public static int getMode(ArrayList<Integer>arr) {
int maxValue = 0, maxCount = 0;
for (int i = 0; i < arr.size(); ++i) {
int count = 0;
for (int j = 0; j < arr.size(); ++j) {
if (arr.get(j) == arr.get(i))
++count;
}
if (count > maxCount) {
maxCount = count;
maxValue = arr.get(i);
}
}
return maxValue;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
ArrayList<Integer>list= new ArrayList<Integer>();
int n;
System.out.println("Enter sequence of numbers (negative number to quit): ");
while(true) {
n=sc.nextInt();
if(n<=0)
break;
list.add(n);
}
System.out.println("Mode : "+getMode(list));
}
}
⇒ the code would produce Mode:6
cheers i hope this helps!!!!