Question: 22. Which code snippet calculates the sum of all the even elements in an array values? Select one: a. int sum = 0; for (int

22.

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

Select one:

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++; 
 } 
} 

23.

Consider the following method:

public static int mystery(int length, int n) 
{ 
 int[] result = new int[length]; 
 for (int i = 0; i < result.length; i++) 
 { 
 result[i] = (int) (n * Math.random()); 
 } 
 return result; 
} 

Which statement is correct about the code?

Select one:

a. The method works perfectly

b. The method returns a random number

c. The method return type should be changed to int[]

d. The method has a bounds error when the array size is too large

24.

Which one of the following is a valid signature of a method with an integer two-dimensional array parameter of size 10 x 10?

Select one:

a. public static void func(int[][] arr)

b. public static void func(int[10][] arr)

c. public static void func(int[][10] arr)

d. public static void func(int[10][10] arr)

25.

Babbages machine for automatically producing printed tables was called

Select one:

a. the slide rule.

b. the difference engine.

c. the mechanical calculator.

d. the cog wheel.

26.

Which code snippet calculates the sum of all the elements in even positions in an array?

Select one:

a.

int sum = 0; 
for (int i = 1; i < values.length; i+=2) 
{ 
 sum++; 
} 

b.

int sum = 0; 
for (int i = 0; i < values.length; i++) 
{ 
 sum++; 
} 

c.

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

d.

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

27.

Consider the following code snippet:

int cnt = 0; 
int[][] numarray = new int[2][3]; 
for (int i = 0; i < 3; i++) 
{ 
 for (int j = 0; j < 2; j++) 
 { 
 numarray[j][i] = cnt; 
 cnt++; 
 } 
} 

What is the value of numarray[1][2] after the code snippet is executed?

Select one:

a. 2

b. 5

c. 3

d. 4

28.

Consider the following code snippet:

String[] data = { "123", "ghi", "jkl", "def", "%&*" }; 

Which statement sorts the data array in ascending order?

Select one:

a. data = Arrays.sort();

b. Arrays.sort(data);

c. data = Arrays.sort(data.length);

d. data = Arrays.sort(data);

29.

When a Java program terminates and reports an exception, the error message contains which pieces of useful information?

I. The compile and revision control history of the source code changes that caused the error

II. The name of the exception that occurred

III. The stack trace

Select one:

a. I, II

b. I, III

c. II, III

d. I, II, III

30.

When an integer literal is added to an array list declared as ArrayList, Java performs:

Select one:

a. casting

b. trimming

c. auto-boxing

d. auto-fixing

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!