Respuesta :
Here it is. Enjoy.
It appears Brainly doesn't like the import statements, so I had to take them out. Can you figure them out by yourself?
You need System, Scanner and DecimalFormat.
public class ArrayDemo
{
private int GetArraySize()
{
Scanner reader = new Scanner(System.in);
int arraySize;
do {
System.out.print("Please enter the size of the array: ");
arraySize = reader.nextInt();
if (arraySize < 1) {
System.out.println("Enter a number larger than 0.");
}
} while (arraySize < 1);
return arraySize;
}
private void FillArray(double[] array, double start, double factor)
{
for(int i=0; i<array.length; i++)
{
array[i] = start+factor*i;
}
}
private void PrintArray(double[] array)
{
for(int i=0; i<array.length; i++)
{
System.out.print(array[i] + " ");
}
System.out.println();
}
private void ReverseArray(double[] array)
{
for(int i=0; i<array.length/2; i++){
double temp = array[i];
array[i] = array[array.length -i -1];
array[array.length -i -1] = temp;
}
}
public void RunDemo(double factor, double start)
{
int arraySize = GetArraySize();
double[] demoArray = new double[arraySize];
FillArray(demoArray, start, factor);
DecimalFormat format = new DecimalFormat("0.#");
System.out.printf("Here is the multiple of %s, starting at %s\n", format.format(factor), format.format(start));
PrintArray(demoArray);
System.out.println("Now in reverse order");
ReverseArray(demoArray);
PrintArray(demoArray);
}
public static void main(String[] args)
{
double factor = 3.0;
double start = 3.5;
ArrayDemo demo = new ArrayDemo();
demo.RunDemo(factor, start);
}
}