Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming with arrays in Java: 1.Write a program that reads an integer from the user, then creates an array of integers of that length. It

Programming with arrays in Java:

1.Write a program that reads an integer from the user, then creates an array of integers of that length. It then fills the array with integers read from the user.

2.In your programs main class, define a static method 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. Extend your program from Question 1 to use this method to print the array after reading it.

3.Extend your program to print the index of the middle element of the array and the value stored in the array at that index (with an informative message). Explain in a comment how you decide what the middle is.

4.Extend your program to compute the minimum value in the array and print it out (with an informative message).

5.Extend your program to read an integer from the user and add it to every element of the array. Print the array after changing it (with an informative message).

6.Extend your program to declare another integer array variable and make its value be a copy of the first array. That is, its value should be a reference to a new array of the same length that contains the same element values (this is called a shallow copy). Print the first and last elements of the copy (with an informative message).

7.Arrays of the same length are added by adding the corresponding elements (i.e., the first element of the sum is the sum of the first elements of each array, same for the second element, and so on). In math:

[a0,a1,...,an] + [b0,b1,...,bn] = [a0 +b0,a1 +b1,...,an +bn]

Extend your program to add the copy of the array to the original. This should change the original array but not the copy. Print both arrays afterwards to show that this is so (with an informative message).

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions