Question
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:
|
| ||
|
| ||
|
| ||
|
|
3. If String str = "The There Here", then what is the value of str.indexOf("he");?
Question 3 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started