Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer the Following Question correctly. 1.Which statements are true regarding the differences between arrays and array lists? I. Arrays are better if the size of

Answer the Following Question correctly.

1.Which statements are true regarding the differences between arrays and array lists?

I. Arrays are better if the size of a collection will not change

II. Array lists are more efficient than arrays

III. Array lists are easier to use than arrays

a) I, II

b) I, III

c) II, III

d) I, II, III

2.The following statement gets an element from position 4 in an array:

x = a[4]; 

What is the equivalent operation using an array list?

a) x = a.get(4);

b) x = a.get();

c) x = a.get[4];

d) x = a[4];

3.Which code snippet calculates the sum of all the even elements in an array values?

a)

int sum = 0; 
for (int i = 0; i < values.length; i++) 
{ 
 if ((values[i] % 2) == 0) 
 { 
 sum += values[i]; 
 } 
} 

b)

int sum = 0; 
for (int i = 0; i < values.length; i++) 
{ 
 if ((values[i] % 2) == 0) 
 { 
 sum++; 
 } 
} 

c)

int sum = 0; 
for (int i = 0; i < values.length; i++) 
{ 
 if ((values[i] / 2) == 0) 
 { 
 sum += values[i]; 
 } 
} 

d)

int sum = 0; 
for (int i = 0; i < values.length; i++) 
{ 
 if ((values[i] / 2) == 0) 
 { 
 sum++; 
 } 
} 

4.Which one of the following code snippets accepts the integer input in an array list named num1 and stores the odd integers of num1 in another array list named oddnum?

a)

ArrayList num1 = new ArrayList(); 
ArrayList oddnum = new ArrayList(); 
int data; 
Scanner in = new Scanner(System.in); 
for (int i = 0; i < 10; i++) 
{ 
 data = in.nextInt(); 
 num1.add(data); 
 if (num1.get(i) % 2 == 0) 
 { 
 oddnum.add(num1.get(i)); 
 } 
} 

b)

ArrayList num1 = new ArrayList(); 
ArrayList oddnum = new ArrayList(); 
int data; 
Scanner in = new Scanner(System.in); 
for (int i = 0; i < 10; i++) 
{ 
 data = in.nextInt(); 
 num1.add(data); 
 if (num1.get(i) % 2 != 0) 
 { 
 oddnum.add(num1.get(i)); 
 } 
} 

c)

ArrayList num1 = new ArrayList(); 
ArrayList oddnum = new ArrayList(); 
int data; 
Scanner in = new Scanner(System.in); 
for (int i = 0; i < 10; i++) 
{ 
 data = in.nextInt(); 
 num1.add(data); 
 if (num1.get(i) % 2 == 0) 
 { 
 oddnum.add(num1[i]); 
 } 
} 

d)

ArrayList num1; 
ArrayList oddnum = new ArrayList(); 
int data; 
Scanner in = new Scanner(System.in); 
for (int i = 0; i < 10; i++) 
{ 
 data = in.nextInt(); 
 num1.add(data); 
 if (num1[i] % 2 != 0) 
 { 
 oddnum.add(num1[i]); 
 } 
} 

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

Strategize e-mail with structured thinking

Answered: 1 week ago