Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A) Write a method with the header public static void process(int[] vals) that takes a reference to an array of integers and modifies its internals

A) Write a method with the header

public static void process(int[] vals) 

that takes a reference to an array of integers and modifies its internals as follows:

If an element is even, it should be doubled.

If an element is odd, it should be negated (i.e., multiplied by -1).

For example, if you add the following test code to your main method:

int[] a1 = {1, 2, 6, 5, -8, -10, -11}; ArrayMethods.process(a1); System.out.println(Arrays.toString(a1)); 

you should see the following output:

[-1, 4, 12, -5, -16, -20, 11] 

Special case: If the parameter is null, the method should throw an IllegalArgumentException.

B) Write a method with the header

public static String[] extractBU(String[] words) 

that takes a reference to an array of strings, and that creates and returns a new array that contains the strings from the original array whose first letter is either 'b', 'B', 'u' or 'U'.

For example:

String[] a2 = {"Build", "up", "your", "best", "self"}; String[] a3 = ArrayMethods.extractBU(a2); System.out.println(Arrays.toString(a3)); 

should display:

[Build, up, best] 

Important:

You may not use any of the built-in methods for copying or extracting a portion of an array.

You must not modify the original array.

The new array (the one that you will return) should not have any extra unused elements. As a result, we recommend making an initial pass through the original array to determine how long the new array should be. Then you can create the new array and make a second pass through the original array to find and copy the appropriate strings.

Special case: If the parameter is null, the method should throw an IllegalArgumentException.

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

Why application developers use UDP protocol for their applications?

Answered: 1 week ago

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Self-Disclosure and Interpersonal Relationships?

Answered: 1 week ago