Now I looked through many other questions to find similar to mine but for some reason I don't understand how to get the array the user entered to display when calculating the average. If there is a question similar to mine, please send me the link that way I can refer to it. Thank you so much. I want it to show:
"Please enter 5 integers: 25 43 12 5 7"
"You have entered: 25 43 12 5 7 and the average is __"
public class CalcAvg {
public static void main(String[] args) {
double [] userinput = getArrayInfo();
double average = CalculateAvg(userinput);
getAvg(userinput, average);
}
public static double[] getArrayInfo() {
Scanner in = new Scanner(System.in);
final int NUM_ELEMENTS = 5;
double[] userinput =new double[NUM_ELEMENTS];
int i = 0;
System.out.println("Please enter 5 integers: ");
for (i = 0; i < NUM_ELEMENTS; ++i) {
userinput[i] = in.nextDouble();
}
return userinput;
}
public static double CalculateAvg(double[] userinput) {
double sum = 0;
double average = 0;
for (int i = 0; i < userinput.length; i++) {
sum = sum + userinput[i];
}
average = sum / userinput.length;
return average;
}
public static void getAvg(double[] userinput, double average) {
int i = 0;
System.out.println("The average of the numbers " + userinput + " is " +average);
}
}