Question
Write a method to calculate and return the product of the values in an array. Declare an array of integer values that will represent the
Write a method to calculate and return the product of the values in an array.
Declare an array of integer values that will represent the first five prime numbers: 2, 3, 5, 7, and 11.
Initialize each element of the array with the prime number values shown above.
Calculate the product of the array elements, and store the result in a variable named product. You must access the array elements to accomplish this. Do not write
product = 2 * 3 * 5 * 7 * 11 ;
or
product = 2310;
Return the product at the end of the method.
2.
The following code segment is part of a bigger program to multiply the corresponding values of two arrays, a1 and a2. Arrays a1 and a2 are declared and initialized to store a certain number of doubles.
public static void newArray()
{double[ ] a1 = new double[some length];
double[ ] a2 = new double[some length];
// Assume that there is code here that prompts the user to enter these double
// values and stores them in a1 and a2. You don't know what the user will type, but
// you may assume that the code is correct and no errors occur in this portion of the program.
// Complete this part of the method
Add code to do the following:
declare an additional array of of doubles (based on the length of a1 or a2)
fill the new array with the product of the corresponding elements in a1 and a2
print the values stored in the new array to the screen
For example, if the first two arrays hold the following values:
{1.2, 2.3, 3.4, 4.5, 5.6} and
{1.0, 2.0, 3.0, 4.0, 5.0},
your array should be filled with the following values:
{1.2, 4.6, 10.2, 18.0, 28.0}
Complete the code segment to accomplish the additional tasks described
3.
int side1;
int side2; //additional vars as needed
/*assume there is code here to initialize these values*/
Two polygons are said to be similar if their corresponding angles are the same or if each pair of corresponding sides has the same ratio. Write a method to test if two right triangles are similar when the measurement of each side is provided as an integer value.
If one set of corresponding sides of the triangles have lengths of 18 and 12, the ratio would be 1.5.
The method needs to return a String stating if the triangles are similar or not.
4.
You are training to complete in a local 5K run. You record your time scores in minutes after completing seven practice runs. Write a method to calculate and return the average score based on the data.
Before calculating the average, you decide to throw out the lowest and highest scores.
Your method should do the following:
Declare and initialize the array with the recorded time scores such as 24.6
Determine the maximum and minimum values in the array
Compute the average of the array contents, excluding the maximum and minimum values (array methods may not be used)Ccalculate and return the average, excluding the maximum and minimum values
Step by Step Solution
3.39 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
1 Method to calculate the product of values in an array java public static int calculateProductint a...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started