Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 17 What is stored in the array arr after the following code executes? int[ ] arr = {17, 34, 43, 71}; int i =

Question 17

What is stored in the array arr after the following code executes? int[ ] arr = {17, 34, 43, 71}; int i = 0; while(i < arr.length) { if((arr[i] % 2) == 1) { arr[i] = arr[i] % 3; } else { arr[i] = arr[i] / 3; } i++; }

A){1, 11, 2, 10}

B){2, 10, 11, 1}

C){2, 11, 1, 2}

D){2, 11, 1, 10}

E)An ArrayIndexOutOfBoundsException occurs.

Question 18

What is the minimum number of locations a sequential search algorithm will have to examine when looking for a particular value in an array of 100 elements?

A)1

B)6

C)7

D)8

E)100

Question 19

Suppose you write a subclass of Insect named Ant. You add a new method named doSomething to the Ant class. You write a client class that instantiates an Ant object and invokes the doSomething method. Which of the following Ant declarations will NOT permit this?

  1. Insect a = new Ant();
  2. Ant a = new Ant();
  3. Ant a = new Insect();

A)I only

B)II only

C)III only

D)I and II only

E)I and III only

Question 20

The following method is intended to remove all values from the ArrayList < Integer > aList that have the same value as val; however, this method does NOT work correctly. public void removeValue(ArrayList < Integer > aList, int val) { int i; for(i = 0; i < aList.size(); i++) { if(aList.get(i) == val) { aList.remove(i); } } } If aList initially contains 2 3 4 3 3 4 4 5 4 3 2 1 and val is equal to 3, then aList should contain 2 4 4 4 5 4 2 1 after removeValue is invoked. What does aList actually contain after removeValue is invoked?

A)2 4 4 4 5 4 2 1

B)2 4 3 4 4 5 4 2 1

C)2 4 4 3 4 4 5 4 2 1

D)2 4 3 4 4 5 4 3 2 1

E)2 4 3 3 4 4 5 4 3 2 1

Question 21

What is output by the following code? ArrayList < Integer > a = new ArrayList < Integer >(); ArrayList b = a; a.add(4); b.add(5); a.add(6); b.add(7); System.out.println(a.get(3));

A)An IndexOutOfBoundsException occurs.

B)4

C)5

D)6

E)7

Question 22

Assume that you have an array of integers named arr. Which of these code segments print the same results?

  1. int i = 0; while(i < arr.length) { System.out.println(arr[i]); i++; }
  2. int i; for(i = 0; i < arr.length; i++) { System.out.println(arr[i]); }
  3. for(int i : arr) { System.out.println(i); }

A)II only

B)I and II only

C)II and III only

D)I and III only

E)I, II, and III

Question 23

Suppose the following array and integer are declared: int[] numbers = {4, 5, 6, 7}; int index = 1 + 6 % 4 * 2; What is the value of numbers[index]?

A)An ArrayIndexOutOfBoundsException occurs.

B)4

C)5

D)6

E)7

Question 24

To extend an abstract class, a class must

A)extend an interface

B)class implement at least one abstract method from the abstract class

C)include new methods

D)specify the keyword implements

E)specify the keyword extends

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions