Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming with Arrays Write a short program to calculate the second derivative of an array of doubles. Starting with Lab.java (shown below), finish the program

Programming with Arrays

Write a short program to calculate the second derivative of an array of doubles. Starting with Lab.java (shown below), finish the program to compute and print the discrete second derivative of the array read in by adding code everywhere it says // [Add code here]. The first line of input will tell how many values are in the array. Next, the data points will be give, one per line. import java.util.*; public class Lab { public static void main(String args[]) { Scanner scan = new Scanner(System.in);

// Read in the number of data points int numDataPoints = scan.nextInt();

// Create an array to hold the data points, and another to // hold the second derivative double data[] = new double[numDataPoints]; double secondDerivative[] = // [Add code here]

// Read in all of the data points using a for loop // [Add code here]

// Print out the data using printArray printArray(data); System.out.println();

// Create the second derivatives and store them in the // secondDerivative array. // (Since the first and last elements of the array do // not have neighbors, set their second derivatives to 0.) // [add code here]

// Print the second derivative array by calling printArray // [add code here] }

public static void printArray(double[] arr) { // Print the values of arr on a single line with spaces between them. // [Add code here] } }

Entering Data and Running the Program Now we need some data. Type in, or copy the following input file, and call it labinput.txt: 9 1.1 2.2 3.3 2.2 1.1 7.0 8.0 9.1 10.0 Run your second derivative program with the input file you have just entered: java Lab < labinput.txt Run the program again, redirecting (use >) the output to labout.txt.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Will Walmart be successful against Amazon.com? Explain your answer.

Answered: 1 week ago

Question

Have roles been defined and assigned?

Answered: 1 week ago