Question: JAVA Create a class FillArray. Do your work in the main() method. Prompt the user with Enter a positive integer:. Set up a Scanner to
JAVA
Create a class FillArray.
Do your work in the main() method.
Prompt the user with "Enter a positive integer:".
Set up a Scanner to read from the keyboard and take in a positive integer arraySize from the user.
Allocate an array whose length is arraySize.
Loop over the elements of the array, assigning the value k*(k-1) to the array element at k (that is, fill array[k] with k*(k-1)).
Now loop over the array again, summing up all the elements of the array.
Print out the sum with "Sum = " and the sum
Also print out "Check = " and the value arraySize * (arraySize - 1) * (arraySize - 2) / 3
In order to pass tests, use the following format:
Enter a positive integer: Sum = <> Check = < >
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
