Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write a method named resize that does the following: Takes in an array Creates an array of double its length Copies the values from

1. Write a method named resize that does the following:

Takes in an array

Creates an array of double its length

Copies the values from the original array into the longer array

Returns the longer array containing the values from the original array.

The method signature should be public static int [ ] resize (int [] arr);

Make more than one version of this method so that it works with different types

(int, char, double, String)

2. Write a void method that takes in an array and prints the elements in reverse order.

The method signature should be public static void printArrReverse (String [] arr);

Make more than one version of this method so that it works with different types

(int, char, double, String)

3. Write a void method that does the following:

Takes in 2 arguments, an int and an int[] arr

Iterates through the array

Prints the product of each value in the array multiplied by the int that was passed in.

The method signature should be public static void printValTimesN (int n, int [] arr);

4. Write a method that does the following:

Takes in an array of type String

Uses Math.random to randomly select an index from 0 to the last index of the array

Return the Word located at that index of the array

The method signature should be public static String [ ] getRandomWord (String [] arr);

5. Write a method that does the following:

Takes in 2 arguments, an int and an int[] arr

Iterates through the array to find if there is a value that matches the target

Returns the index if a match was found

Returns -1 if the entire array was traversed without finding a match

The method signature should be public static int findMatch (int target, int [] arr);

6. Write a method that does the following:

Takes in an array containing values of type int

Iterates through the array

Calculates the average and returns it

The method signature should be public static double getAverage (int [] arr);

Test each method by calling it with different values and checking that the output was what you expected.

Hint for the methods that dont print, youll need to store the returned result in a variable before printing it.

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_2

Step: 3

blur-text-image_3

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

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions