Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. How many dimensions are in the array? char[][] array1 = new char[15][10]; Question 2 options: 1) 0 2) 1 3) 2 4) 3 3.

2. How many dimensions are in the array?

char[][] array1 = new char[15][10];

Question 2 options:

1)

0

2)

1

3)

2

4)

3

3. If String str = "The There Here", then what is the value of str.indexOf("he");?

Question 3 options:

1)

0

2)

1

3)

2

4)

5

5)

e. -1

4. What is the value of vals[1][2]?

double[][] vals = {{1.1, 1.3, 1.5}, {3.1, 3.3, 3.5}, {5.1, 5.3, 5.5}, {7.1, 7.3, 7.5}}

Question 4 options:

1)

1.3

2)

3.3

3)

3.5

4)

5.3

5. Consider the method total below.

public static int total (int result, int a, int b) { if (a == 0) { if (b == 0) { return result * 2; } return result / 2; } else { return result * 3; } } The assignment statement x = total (1,1, 1); must result in

Question 5 options:

1)

x being assigned the value 3

2)

x being assigned the value 7

3)

x being assigned the value 5

4)

x being assigned the value 2

5)

x being assigned the value 0

6. Which of the following statements creates alpha, a two-dimensional array of 10 rows and 5 columns, wherein each component is of the type int? (1 point)

i. int[][] alpha = new int[10][5];

ii. int[][] alpha; alpha = new int[10][]; for (int i = 0; i < 10; i++) alpha[i] = new int[5];

Question 6 options:

1)

Only (i)

2)

Only (ii)

3)

Both (i) and (ii)

4)

None of these

Consider the method total below.

public static int total (int result, int a, int b) { if (a == 0) { if (b == 0) { return result * 2; } return result / 2; } else { return result * 3; } } The assignment statement x = total (6, 0, 0); must result in

Question 7 options:

1)

x being assigned the value 8

2)

x being assigned the value 4

3)

x being assigned the value 5

4)

x being assigned the value 12

5)

x being assigned the value 10

8. Consider the following declarations.

public class List { private static final int MAX_ITEMS = < some value >; private int[] items; private int numItems; // constructor(s) and other methods not shown //precondition: 0 <= numItems < MAX_LENGTH public int find (int num) { boolean found = false; int loc = 0; while (!found && loc < numItems) { if (items[loc] == num) { found = true; } loc++; } if (!found) { loc = -1; } return loc; } }

Which of the following is a correct postcondition for the find method?

Question 8 options:

1)

returns true if num is found in this list; false otherwise

2)

returns true if num is found in this list; void otherwise

3)

returns the number of items currently in this list

4)

returns -1 if num is not in list; index of num otherwise

5)

returns index of num if num is in this list; nothing otherwise

9. What is the output of the program shown below?

public class SomeClass { private int x, y; public SomeClass (int xValue, int yValue) { x = xValue; y = yValue; } public void m1() { x = 30; System.out.print((y + 1) + " "); } public void m2() { m1(); System.out.print(x + " "); } } public class Tester { public static void main (String[] args) { int x = 20; int y = 10; SomeClass z = new SomeClass(y, x); z.m2(); z.m1(); } }

Question 9 options:

1)

21 10 21

2)

21 30 21

3)

11 30 11

4)

1 10 11

5)

11 30 21

10. What is output by the following code?

public class Swapper

{ private int a, b; public Swapper(int aValue, int bValue) { a = aValue; b = bValue; } public void swap () { a = b; b = a; } public void print () { System.out.println("a = " + a + ", and b = " + b); } } public class Tester { public static void main(String[] args) { Swapper swapObj = new Swapper(10, 20); swapObj.swap(); swapObj.print(); } }

Question 10 options:

1)

a = 10, and b = 20

2)

a = 20, and b = 10

3)

a = 10, and b = 10

4)

a = 20, and b = 20

5)

None of the above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

How can Trip 7 prevent future supply chain uncertainties?

Answered: 1 week ago