Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

12. Refer to the following code: private int[] arr; //precondition: arr.length > 0 public void mystery() { int s1 = 0; int s2 = 0;

12. Refer to the following code:

private int[] arr;

//precondition: arr.length > 0 public void mystery() { int s1 = 0; int s2 = 0;

for (int k = 0; k < arr.length; k++) { int num = arr[k]; if ((num > 0) && (num % 2 == 0)) s1 += num; else if (num < 0) s2 += num; } System.out.println (s1); System.out.println (s2);

Which of the following best describes the value of s2 output by the method mystery?

Question 12 options:

The sum of all negative even values in arr

The sum of all positive even values in arr

The sum of all negative values in arr

The sum of all positive values in arr

The sum of all negative odd values in arr

13. Consider the following two data structures for storing several million words.

I. An array of words, not in any particular order

II. An array of words, sorted in alphabetical order

Which of the following statements most accurately describes the time needed for operations on these data structures?

Question 13 options:

Finding a given word is faster in I than in II.

Finding the first word in alphabetical order is faster in I than in II.

Inserting a word is faster in II than in I.

Finding a given word is faster in II than in I.

Finding the longest word is faster in II than in I.

14. Consider the following static method.

public static int calculate(int x) { x = x + x; x = x + x; x = x + x;

return x; }

Which of the following can be used to replace the body of calculate so that the modified version of calculate will return the same result as the original version for all x?

Question 14 options:

return 8 * x;

return 3 * x;

return 3 + x;

return 4 * x;

return 6 * x;

15. Consider the following static method.

private static void recur(int n) { if (n != 0) { recur (n - 2); System.out.println (n + " " ); } }

What numbers will be printed as a result of the call recur(6)?

Question 15 options:

6 4 2 0

No numbers will be printed because of infinite recursion.

-2 0 2 4 6

0 2 4 6

Many numbers will be printed because of infinite recursion.

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

=+ Is secondary industrial action common and/or legal?

Answered: 1 week ago

Question

=+What sanctions are available to employers

Answered: 1 week ago

Question

=+ If strikes occur, are they legally regulated?

Answered: 1 week ago