# Assume double[][] x = new double. what are x.length and x.length?

0

QUESTION 1

Assume double[][] x = new double, what are x.length and
x.length?

4 and 4

4 and 5

5 and 4

5 and 5
1 points Saved
QUESTION 2

What is the output of the following code?

System.out.println(indexOfMax);

1

2

3

4
1 points Saved
QUESTION 3

What is the output of the following code?

1 2 3 4

4 5 6 7

1 3 8 12

2 5 9 13

3 6 10 14
1 points Saved
QUESTION 4

In the following code, what is the printout for list1?

1 2 3

1 1 1

0 1 2

0 1 3
1 points Saved
QUESTION 5

Assume char[][][] x = new char, what are x.length,
x.length, and x.length?

13, 5, and 16

13, 5, and 15

12, 5, and 15

14, 5, and 16
1 points Saved
QUESTION 6

Suppose int[] numbers = new int, what is numbers?

undefined

10

null
1 points Saved
QUESTION 7

When you create an array using the following statement, the
element values are automatically initialized to 0.

int[][] matrix = new int;

true

false
1 points Saved
QUESTION 8

Analyze the following code.

The program has a compile error because the size of the array
wasn’t specified when declaring the array.

The program has a runtime error because the array elements are not
initialized.

The program runs fine and displays x is 0.

The program has a runtime error because the array element x is
not defined.
1 points Saved
QUESTION 9

Analyze the following code:

The program displays 1 2 3 4

The program displays 0 0

The program has a compile error on the statement x = new int,
because x is final and cannot be changed.

The elements in the array x cannot be changed, because x is
final.
1 points Saved
QUESTION 10

What is the output of the following code?

120 200 16

120 200 14

120 200 20

016 is a compile error. It should be written as 16.
1 points Save Answer
QUESTION 11

Which of the following is correct to create an array?

int[] m = {1, 2, };

int[] m = {{1, 2}};

int[] m = {{1, 2}, {3, 4}};

int[] m = {1, 2, 3};
1 points Save Answer
QUESTION 12

The arraycopy method does not allocate memory space for the
target array. The target array must already be created with memory
space allocated.

true

false
1 points Saved
QUESTION 13

Analyze the following code:

The program displays 0 1 2 3 4.

The program displays 0 1 2 3 4 and then raises a runtime
exception.

The program displays 0 1 2 3 4 5.

The program displays 0 1 2 3 4 5 and then raises a runtime
exception.
1 points Save Answer
QUESTION 14

Use the selectionSort method presented in this section to answer
this question. Assume list is {3.1, 3.1, 2.5, 6.4, 2.1}, what is
the content of list after the first iteration of the outer loop in
the method?

3.1, 3.1, 2.5, 6.4, 2.1

2.5, 3.1, 3.1, 6.4, 2.1

2.1, 2.5, 3.1, 3.1, 6.4

3.1, 3.1, 2.5, 2.1, 6.4

2.1, 3.1, 2.5, 6.4, 3.1
1 points Saved
QUESTION 15

Suppose array a is int[] a = {1, 2, 3}, what is a –
a?

1

2

3

-1

-2
1 points Saved
QUESTION 16

Assume int[][][] x = new char, how many elements are in
the array?

30

35

40

45
1 points Saved
QUESTION 17

Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length
are x.length?

2 and 1

2 and 2

3 and 2

2 and 3

3 and 3
1 points Saved
QUESTION 18

Analyze the following code:

The program displays 1 2 3 4 5.

The program displays 1 2 3 4 5 and then raises an
ArrayIndexOutOfBoundsException.

The program displays 5 4 3 2 1.

The program displays 5 4 3 2 1 and then raises an
ArrayIndexOutOfBoundsException.
1 points Save Answer
QUESTION 19

What is the printout of the following program?

1

3

5

6

33
1 points Save Answer
QUESTION 20

What is the output of the following code?

1 2 3 4 5 6

2 3 4 5 6 6

2 3 4 5 6 1

1 1 1 1 1 1
1 points Save Answer
QUESTION 21

Which correctly creates an array of five empty Strings?

String[] a = new String ;

String[] a = {“”, “”, “”, “”, “”};

String a;

String[ ] a = new String ; for (int i = 0; i < 5; a[i++]
= null);
1 points Saved
QUESTION 22

Also Check This  Do any of you have rabbits who like to eat saltine crackers?

What is the representation of the third element in an array
called a?

a

a(2)

a

a(3)
1 points Saved
QUESTION 23

What is the printout of the following program?

1

3

5

6

33
1 points Save Answer
QUESTION 24

Analyze the following code:

The program displays 1 2 3 4

The program displays 0 0

The program displays 0 0 3 4

The program displays 0 0 0 0
1 points Save Answer
QUESTION 25

Analyze the following code:

The program has a compile error because new boolean[] is
wrong.

The program has a runtime error because x is null.

The program runs and displays x is null.

The program runs and displays x is true.

The program runs and displays x is false.
1 points Save Answer
QUESTION 26

Given the following program:

What is the output, if you run the program using the
following?

java Test 1 2 3

3

1

1 2 3

1 2
1 points Save Answer
QUESTION 27

What would be the result of attempting to compile and run the
following code?

The program has a compile error because the syntax new double[]{1,
2, 3} is wrong and it should be replaced by {1, 2, 3}.

The program has a compile error because the syntax new double[]{1,
2, 3} is wrong and it should be replaced by new double{1, 2,
3};

The program has a compile error because the syntax new double[]{1,
2, 3} is wrong and it should be replaced by new double[]{1.0, 2.0,
3.0};

The program compiles and runs fine and the output “Value is 1.0” is
printed.

The program compiles and runs fine and the output “Value is 2.0” is
printed.
1 points Save Answer
QUESTION 28

Suppose a method p has the following heading:

public static int[] p()

What return statement may be used in p()?

return 1;

return {1, 2, 3};

return int[]{1, 2, 3};

return new int[]{1, 2, 3};
1 points Save Answer
QUESTION 29

Assume int[][] x = {{1, 2, 3}, {3, 4, 5, 5}, {5, 6}}, what are
x.length are x.length?

2

3

4

5
1 points Save Answer
QUESTION 30

Which of the following are valid array declarations?

char[] charArray = new char;

int[] words = new words;

char[] charArray = “Computer Science”;

double nums = {3.5, 35.1, 32.0};
1 points Save Answer
QUESTION 31

Given the following declaration:

Which of the following statements is true?

The name m represents a two-dimensional array of 30 int
values.

m represents the element stored in the 2nd row and the 4th
column of m.

m.length has the value 6.

m.length has the value 5.
1 points Save Answer
QUESTION 32

Analyze the following code.

int[] list = new int;
list = new int;

The code has compile errors because the variable list cannot be
changed once it is assigned.

The code has runtime errors because the variable list cannot be
changed once it is assigned.

The code can compile and run fine. The second line assigns a new
array to list.

The code has compile errors because you cannot assign a different
size array to list.
1 points Save Answer
QUESTION 33

Analyze the following code:

The program displays 2.5, 3, 4

The program displays 2.5 3 4

The program displays 2.5 3.0 4.0

The program displays 2.5, 3.0 4.0

The program has a syntax error because value is undefined.
1 points Save Answer
QUESTION 34

Analyze the following code:

The program displays 0 1 2 3 4.

The program displays 4.

The program has a runtime error because the last statement in the
main method causes ArrayIndexOutOfBounds exception.

The program has a syntax error because i is not defined in the last
statement in the main method.
1 points Save Answer
QUESTION 35

What is the index variable for the element at the first row and
first column in array a?

a

a

a

a
1 points Save Answer
QUESTION 36

Also Check This  Why is Coors called the Banquet Beer?

The element in the array must be of a primitive data type.

true

false
1 points Save Answer
QUESTION 37

When you return an array from a method, the method returns
________.

a copy of the array

a copy of the first element

the reference of the array

the length of the array
1 points Save Answer
QUESTION 38

Which of the following statements are correct?

char[][] charArray = {‘a’, ‘b’};

char charArray = {{‘a’, ‘b’}, {‘c’, ‘d’}};

char[] charArray = {{‘a’, ‘b’}, {‘c’, ‘d’}};

char[][] charArray = {{‘a’, ‘b’}, {‘c’, ‘d’}};
1 points Save Answer
QUESTION 39

Consider the following statements:

int[][] numbers = {{1}, {1, 2}, {1, 2, 3}};

What is numbers.length and what is numbers.length?

3, 1

3, 2

3, 3

1, 3
1 points Save Answer
QUESTION 40

How many elements are array matrix (int[][] matrix = new
int)?

14

20

25

30

(1)   x is an array of double array’s.

In the given example,

(i)
x refers to four double arrays (each of length 5). Hence x.length
returns 4

(ii)   x refers to
double array of size 5. Hence x.length returns 5

Hence Correct option is 4 and
5

______________________________________________________________________________________________________________

For Questions 2, 3, 4 codes are missing in the question.

______________________________________________________________________________________________________________

(5)   x is three dimensional char array.

In the given example,

(i)
x refers to 14 two dimensional char arrays. Hence x.length returns
14

(ii)   x refers to 5
two dimensional char arrays. Hence x.length returns 5

(iii)   x refers to
char array of size 16. Hence x.length returns 16

Hence Correct option is 14, 5 and
16

______________________________________________________________________________________________________________

(6)   numbers is an integer array of size 10.

In this array was declared but array was not
initialized. By default for an integer array, zero(0) is assigned
as default value.

Hence correct option is 0
______________________________________________________________________________________________________________

(7)   If an array was declared and if values are not
initialized, following are the default values based on data
type:

For int : 0
For double : 0.0
For String : null
For boolean : false
For User Defined Type : null

In the given code, matrix is of integer data type.
Hence the default value will be 0

Hence the correct option is true
______________________________________________________________________________________________________________

For Questions (8) (9) (10), Codes are missing.
______________________________________________________________________________________________________________

(11)   Following are the two ways that are correct to
create an array:

(i)
int[] m = {1, 2, };

This is valid
way of creating an array. Trailing comma gets ignored
automatically.

(ii)   int[] m = {1, 2,
3};

Creates an array
of size 3

______________________________________________________________________________________________________________

(12)   arrayCopy method doesn’t allocate memory space
for the target array. The target array should be created in prior
with memory space allocated.

Hence correct option is true
______________________________________________________________________________________________________________

Question (13)   Code is missing
______________________________________________________________________________________________________________

(14)   Selection sort first searches for either
minimum or maximum element first and then replaces it with element
at first position.

After first iteration of outer
loop, content of list is:

2.1, 3.1, 2.5, 6.4, 3.1

______________________________________________________________________________________________________________

(15)   Array a is declared of size 3 with elements 1,
2, 3 at indexes 0, 1, 2 respectively.

s is 1 and a is 3.

Hence a – a is -2 (1-3)

Correct answer is -2

______________________________________________________________________________________________________________

(16)   Statement int[][][] x = new char
raises an error.

incompatible types: char[][][]
cannot be converted to int[][][]

______________________________________________________________________________________________________________

(17)   x is a 2D array. x refers to 3 arrays each of
size 2. Hence x.length returns 3.

x refers to single array of size
2. Hence x.length returns 2

Hence correct option is 3 and
2
______________________________________________________________________________________________________________

For Questions (18) (19) (20) Codes are missing
______________________________________________________________________________________________________________

(21)   String array declared without initialization
holds null values but not empty strings.

Hence the correct way to create
an array of five empty Strings is:

String[] a = {“”, “”, “”, “”,
“”};
______________________________________________________________________________________________________________

Also Check This  find the second solution for this differential equation: xy” + y’ = 0 ; y1= lnx?

(22)   Array indexing starts from 0 to length-1.

For example, an array of
declaration a holds elements at indexes 0, 1, 2, 3 and 4
respectively.

Hence third element of array a is
a
______________________________________________________________________________________________________________

For Questions (23)(24)(25)(26)(27) Codes are missing
______________________________________________________________________________________________________________

(28)   Return value of method p should be an integer
array.

In the given options,

Option ” return new int[]{1, 2, 3};
” creates a new array and returns to called function.

Hence correct option is return new
int[]{1, 2, 3};

______________________________________________________________________________________________________________

(29)   x is a two dimensional integer array.

x refers to 3 single dimensional
arrays. Hence x.length returns 3

x refers to a single dimensional
array of size 4({3, 4, 5, 5}). Hence x.length returns 4

Hence correct option is 3 and
4

______________________________________________________________________________________________________________

(30)
(i)
char[] charArray = new char; is a valid declaration. It creates
a char array of length 26.

(ii)   int[] words = new
words; is not a valid declaration. words is not a data
type.

(iii)   char[] charArray
= “Computer Science”; is not a valid declaration. String enclosed
in double quotes refers to data-type String and    array
is of char data-type.

(iv)   double nums =
{3.5, 35.1, 32.0}; is not a valid declaration. Array size should be
not be specified there.

______________________________________________________________________________________________________________

For Question (31)   declaration is missing in the
question.
______________________________________________________________________________________________________________

(32)   Given code can compile and run fine. The second
line assigns a new array to list.

Initially array list was
declared to be of size 5.

In the next statement, a new array
of size 6 is created and assigned.
______________________________________________________________________________________________________________

For Question (33) (34) Codes are missing
______________________________________________________________________________________________________________

(35)   In a two dimensional array, indexing starts
from 0, 0.

Row indexing starts from 0 and
column indexing starts from 0.

Hence element at the first row and
first column in array a is accessed as a
______________________________________________________________________________________________________________

(36)   Elements of the array can be of any type. There
is no restriction of them to be of primitive data type.

Hence correct option is
False

______________________________________________________________________________________________________________

(37)   When you return an array from a method, the
method returns reference of the array.

For example:

public static
int[] meth( )
{

int[] x = new int;    //
Create an array of size 2 elements

x = 2;

x = 3;

return
x;         // Return the
reference of the array. i.e., location of the array
}
______________________________________________________________________________________________________________

(38)
(i)
Statement, char[][] charArray = {‘a’, ‘b’}; is not correct as
charArray is declared to be of two dimensional char array but
passing two characters.

(ii)   char
charArray = {{‘a’, ‘b’}, {‘c’, ‘d’}}; is not correct as size should
not be specified there.

(iii)   char[]
charArray = {{‘a’, ‘b’}, {‘c’, ‘d’}}; is not correct as size should
not be specified there.

(iv)   char[][] charArray
= {{‘a’, ‘b’}, {‘c’, ‘d’}}; is a Correct statement. It creates a
two dimensional char array.

______________________________________________________________________________________________________________

(39)   Array numbers is of two dimensional
array.

(i)
numbers refers to three single dimensional array. Hence
numbers.length returns 3

(ii)   numbers refers
to a single dimensional array of size 2. Hence numbers.length
returns 2

Hence correct option is 3, 2

______________________________________________________________________________________________________________

(40)   matrix is a two dimensional array with five
rows and five columns.

For any two dimensional array of p
rows and q columns, size = p * q

Therefore number of elements in the
array matrix is 25 (5 * 5). 