Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!