So to summarize my problem, I want the function int[] get_marks() to be able to return the array, but I don't know how to get my ArrayList marks to convert into an array which I can use the return thing for. I need the arraylist to be converted because I need to be able to find the frequency and mode of the array (parts of the code I have not started because I can't figure out how to convert the arraylist).
Below is my comment less code so far.
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
class Main {
public static int[] get_marks(){
Scanner input = new Scanner(System.in);
ArrayList<Integer> marks = new ArrayList<>();
final int FLAG = -1;
int entries = 0;
System.out.println("Enter your marks. Type -1 when done.");
while (entries != FLAG){
entries = input.nextInt();
if (entries >=0 && entries <= 100){
marks.add(entries);
} else if (entries == FLAG) {
break;
} else {
System.out.println("Invalid entry. Marks must be between 0-100.");
}
}
input.close();
System.out.println("Your Marks are: " + marks);
}
public static void main(String[] args) {
get_marks();
System.out.println();
}
}