/*Write a program that reads an unspecified number of scores (score can be double
and int), based on value of the score store it in appropriate array of its type,
determine how many scores are above or equal to the average and how many
scores are below the average. Enter a negative number to signify the end of the
input. Assume that the maximum number of scores is 100. Write two overloaded
methods that return the average of score with the following headers:
public static int average(int[] array)
public static double average(double[] array)*/
import java.util.*;
public class scorebyme{
public static int average(int[] array){
int average=0 , count=0;
//int[] array1 = new int[10];
for(int i = 1; i<=10; i++){
if(array[i]<0)
break;
average = average+array[i];
count++;
}
average = (average/count);
int aboveOrEqual=0 , below=0;
for(int i = 1; i<=count; i++){
if(array[i]>=average){
aboveOrEqual++;
}
else{
below++;
}
}
return 1;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the scores:(entering negative will terminate the program::): ");
int[] score = new int[10];
for(int i = 1; i<=10; i++){
score[i] = sc.nextInt();
}
average(score);
}
}
// getting problem of arrayindex out of bound. in this i have take 100 user input and then //do their average and then how many are above or equal or below average. pls help not getting over it.