Hi. im doing some exercises and im confused as to what its asking me to do.
Problem: write a program that displays the average and highest mark based on the sets of marks entered. values less than 0 and greater than 100 should be ignored
input: a list of input that contains integer with the range and inclusive of 0 to 100 and ends with -1
i did some coding(to test) but still confused:
import java.util.Arrays;
import java.util.Scanner;
public class meanAndMax {
public static void main(String[] args) {
//create/initialize scanner
Scanner sc = new Scanner(System.in);
//float result;
System.out.println("How many numbers would you like to insert?");
int num = sc.nextInt();
int[] array = new int[num];
System.out.println("Please enter the data : ");
for(int i=0; i<array.length; i++){
array[i] = sc.nextInt();
}
System.out.println(Arrays.toString(array));
sc.close();
}
}
i used array to store the marks to be entered but is that the right way? can i just insert the marks without knowing the array size but itll just expand on its own? because size of array is not given so i have to prompt the user for the how many numbers they want to insert.
But to me like if i was to key in marks i dont want to have to count how many marks there are only then i can key in the marks i would rather just key in the marks straight away. is there a different way to approach this? sorry new to java doing a few different exercises.
i was thinking like the users enter numbers then a count variable will count how many has been inserted then go from there but then i would need to store the numbers somewhere so this way i wouldnt have to prompt user for how many marks they want to enter.
guidance much appreciated.
thanks in advance!