Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please answer all the question in Java thx Questions 1. Arrays are easy to use in Java. An array variable must be declared, and the

image text in transcribed
image text in transcribedplease answer all the question in Java thx
Questions 1. Arrays are easy to use in Java. An array variable must be declared, and the array itself must be allocated via the keyword new. For example, the line below creates an array named "x" with enough space for 13 integers: int[] x = new int [13]; Write a program which asks the user how many values they would like to process, then creates an array of the specified length, and reads the specified number of values and stores them in the array you created. You may assume all values are integers. 2. Arrays can be passed to methods as arguments/parameters just like other types of data. In your program's main class, define a static method named printArray that takes an array of integers as its only argument and prints the elements of the array. You should print all the elements of the array on one line, separated by spaces, with no extra space after the last element. Hint 1: You may want to use the length property of the array to know how many elements to print. Hint 2: your method should look something like this: public static void printArray(int[] x) { // code to print array x goes here } Lab continues on second page 3. Write another static method named arrayMean which takes an array as a parameter and returns a floating point value which is the mean value (i.e., the average) of the array elements. If A = {1, 2, 3) then arrayMean(A) should return (1+2+3)/3 = 2.0. Modify your main method to print the mean of the user input from the first question 4. A Java array is a great way to represent a vector from regular math. Write another static method named dotProd which takes two arrays as parameters and returns the vector dot product, which is obtained by multiplying each element and computing the sum according to the expression EN-A[n]. B[n] where N is the number of elements in each of the arrays. Note that this method only makes sense if A and B have the same number of elements, and note that this method should not modify either array. As a test, if A - {1, 2, 3) and B = {4, 5, 6) then dotProd (A,B) should return 1.4+2 5+3.6 = 32. Modify your main method to print the dot product of the user's input array with itself. Note that this value should never be negative. An example session with the complete program might look like this: How many numbers to process? > 4 > 3 2 1 4 You entered: 3 2 1 4 Mean: 2.5 Self Dot Product: 27 Note: the user input is indicated by beginning the line with

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

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

Students also viewed these Databases questions

Question

Explain the importance of HRM to all employees.

Answered: 1 week ago