ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 9 Weeks Ago, 4 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 06 Jun 2017 My Price 9.00

code snippet calculates the sum

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.

Babbage’s 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<Integer>, Java performs:

Select one:

a. casting

b. trimming

c. auto-boxing

d. auto-fixing

Answers

(11)
Status NEW Posted 06 Jun 2017 12:06 AM My Price 9.00

-----------

Not Rated(0)