Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Java program that reads 10 numbers from the console (Scanner input = ne

ID: 3858426 • Letter: C

Question

Create a Java program that reads 10 numbers from the console (Scanner input = new Scanner(System.in);)

Store the numbers as Floats in the array.

Create static methods to perform the following actions on the array and returns the result.

Add all the items in the array and return the result. Name this method "add"

Subtract all the items in the array and return the result. Name this method "sub

Multiply all the items in the array and return the result. Name this method "multiply"

Divide all the items in the array and return the result. Name this method "divide"

Explanation / Answer

public static void main(String[] args) {

float[] myArray = new float[10];
Scanner input = new Scanner(System.in);

for (int i = 0; i < myArray.length; i++) {
System.out.println("please enter number");
myArray[i] = input.nextFloat();
}
System.out.println(add(myArray)); // need to make this call
System.out.println(sub(myArray));
System.out.println(mult(myArray));
System.out.println(div(myArray));
}

public static float add(float[] array) {
float sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
}
return sum;
}

public static float sub(float[] array) {
float sub = array[0];
for (int i = 1; i < array.length; i++) {
sub -= array[i];
}
return sub;
}

public static float mult(float[] array) {
float mult = 1;
for (int i = 0; i < array.length; i++) {
mult *= array[i];
}
return mult;
}

public static float div(float[] array) {
double[] divisionResult = new double[array.length / 2];
for(int i = 1; i < array.length; i += 2) {
double result = digit[i];
if (result > digit[i + 1])
result = result / digit[i + 1];
else {
result = digit[i + 1] / result;
}
divisionResult[i / 2] = result;
return result;
}
}