java final exam (ch 6-10)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Assume StringBuilder strBuf is "ABCCEFC", after invoking ________, strBuf contains "ABTTEFT". ) Answers: A. strBuf.replace('C', 'T') B. strBuf.replace('C', "TT") C. strBuf.replace(2, 7, "TTEFT") D. strBuf.replace("CC", "TT") E, strBuf.replace("C", "T")

Assume StringBuilder strBuf is "ABCCEFC", after invoking ________, strBuf contains "ABTTEFT". Selected Answer: C. Correct strBuf.replace(2, 7, "TTEFT") Answers: A. strBuf.replace('C', 'T') B. strBuf.replace('C', "TT") C. Correct strBuf.replace(2, 7, "TTEFT") D. strBuf.replace("CC", "TT") E, strBuf.replace("C", "T")

Assume StringBuilder strBuf is "ABCDEFG", after invoking ________, strBuf contains "AEFG". Answers: A. strBuf.delete(1, 4) B. strBuf.delete(2, 4) C. strBuf.delete(0, 3) D. strBuf.delete(1, 3)

Assume StringBuilder strBuf is "ABCDEFG", after invoking ________, strBuf contains "AEFG". Selected Answer: A. Correct strBuf.delete(1, 4) Answers: A. Correct strBuf.delete(1, 4) B. strBuf.delete(2, 4) C. strBuf.delete(0, 3) D. strBuf.delete(1, 3)

Assume double[][] x = new double[4][5], what are x.length and x[2].length? Answers: A. 5 and 5 B. 4 and 4 C. 4 and 5 D. 5 and 4

Assume double[][] x = new double[4][5], what are x.length and x[2].length? Selected Answer: C. Correct 4 and 5 Answers: A. 5 and 5 B. 4 and 4 C. Correct 4 and 5 D. 5 and 4

Assume int[] scores = {1, 20, 30, 40, 50}, what is the output of System.out.println(java.util.Arrays.toString(scores))? Answers: A. [1, 20, 30, 40, 50] B. {1 20 30 40 50} C. [1 20 30 40 50] D. {1, 20, 30, 40, 50}

Assume int[] scores = {1, 20, 30, 40, 50}, what is the output of System.out.println(java.util.Arrays.toString(scores))? Selected Answer: A. Correct [1, 20, 30, 40, 50] Answers: A. Correct [1, 20, 30, 40, 50] B. {1 20 30 40 50} C. [1 20 30 40 50] D. {1, 20, 30, 40, 50}

Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 3) return? Answers: A. -1 B. -2 C. 1 D. 2 E. 0

Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 3) return? Selected Answer: B. Correct -2 Answers: A. -1 B. Correct -2 C. 1 D. 2 E. 0

Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 30) return? java Test "+" 3 "abc" 2 Answers: A. 0 B. -2 C. -1 D. 2 E. 1

Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 30) return? java Test "+" 3 "abc" 2 D. Correct 2 Answers: A. 0 B. -2 C. -1 D. Correct 2 E. 1

Assume int[][] x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}, what are x[0].length, x[1].length, and x[2].length? Answers: A. 3, 3, and 3 B. 2, 2, and 2 C. 2, 3, and 4 D. 2, 3, and 3 E. 3, 3, and 4

Assume int[][] x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}, what are x[0].length, x[1].length, and x[2].length? Answers: A. 3, 3, and 3 B. 2, 2, and 2 C. Correct 2, 3, and 4 D. 2, 3, and 3 E. 3, 3, and 4

Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length? Answers: A. 3 and 2 B. 2 and 2 C. 2 and 1 D. 2 and 3 E. 3 and 3

Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length? Selected Answer: A. Correct 3 and 2 Answers: A. Correct 3 and 2 B. 2 and 2 C. 2 and 1 D. 2 and 3 E. 3 and 3

Assume s is "ABCABC", the method ________ returns an array of characters. A. toChars(s) B. s.toCharArray() C. String.toCharArray() D. s.toChars() E. String.toChars()

Assume s is "ABCABC", the method ________ returns an array of characters. A. toChars(s) B. Correct s.toCharArray() C. String.toCharArray() D. s.toChars() E. String.toChars()

6.13 What is the output of the following code? double[] myList = {1, 5, 5, 5, 5, 1}; double max = myList[0]; int indexOfMax = 0; for (int i = 1; i < myList.length; i++) { if (myList[i] > max) { max = myList[i]; indexOfMax = i; } } System.out.println(indexOfMax); A. 0 B. 1 C. 2 D. 3 E. 4

B Correct 1

6.31 Analyze the following code: public class Test1 { public static void main(String[] args) { xMethod(new double[]{3, 3}); xMethod(new double[5]); xMethod(new double[3]{1, 2, 3}); } public static void xMethod(double[] a) { System.out.println(a.length); } } Answers: A. The program has a compile error because xMethod(new double[]{3, 3}) is incorrect. B. The program has a compile error because xMethod(new double[5]) is incorrect. C. The program has a compile error because xMethod(new double[3]{1, 2, 3}) is incorrect. D. The program has a runtime error because a is null.

C. Correct The program has a compile error because xMethod(new double[3]{1, 2, 3}) is incorrect.

Identify the problems in the following code. public class Test { public static void main(String argv[]) { System.out.println("argv.length is " + argv.length); } } Answers: A. The program has a compile error because String argv[] is wrong and it should be replaced by C. String[] args. B. The program has a compile error because String args[] is wrong and it should be replaced by String args[]. C. If you run this program without passing any arguments, the program would have a runtime error because argv is null. D. If you run this program without passing any arguments, the program would display argv.length is 0.

D. Correct If you run this program without passing any arguments, the program would display argv.length is 0.

Does the return statement in the following method cause compile errors? public static void main(String[] args) { int max = 0; if (max != 0) System.out.println(max); else return; } A. Yes B. No

Does the return statement in the following method cause compile errors? public static void main(String[] args) { int max = 0; if (max != 0) System.out.println(max); else return; } A. Yes Correct B. No

Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as ________, which stores elements in last-in first-out fashion. Answers: A. a stack B. an array C. storage area D. a heap

Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as ________, which stores elements in last-in first-out fashion. Selected Answer: A. Correct a stack Answers: A. Correct a stack B. an array C. storage area D. a heap

Given the following method static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n--; } } What is k after invoking nPrint("A message", k)? int k = 2; nPrint("A message", k); A. 0 B. 1 C. 2 D. 3

Given the following method static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n--; } } What is k after invoking nPrint("A message", k)? int k = 2; nPrint("A message", k); A. 0 B. 1 C. Correct 2 D. 3

Given the following program: public class Test { public static void main(String[] args) { for (int i = 0; i < args.length; i++) { System.out.print(args[i] + " "); } } } What is the output, if you run the program using java Test 1 2 3? Answers: A. 1 2 B. 1 2 3 C. 3 D. 1

Given the following program: public class Test { public static void main(String[] args) { for (int i = 0; i < args.length; i++) { System.out.print(args[i] + " "); } } } What is the output, if you run the program using java Test 1 2 3? Selected Answer: B. Correct 1 2 3 Answers: A. 1 2 B. Correct 1 2 3 C. 3 D. 1

How can you get the word "abc" in the main method from the following call? java Test "+" 3 "abc" 2 Answers: A. args[1] B. args[3] C. args[0] D. args[2]

How can you get the word "abc" in the main method from the following call? java Test "+" 3 "abc" 2 Selected Answer: D. Correct args[2] Answers: A. args[1] B. args[3] C. args[0] D. Correct args[2]

How can you initialize an array of two characters to 'a' and 'b'? Answers: A. char[] charArray = new char[]{'a', 'b'}; B. char[] charArray = {'a', 'b'}; C. char[2] charArray = {'a', 'b'}; D. char[] charArray = new char[2]; charArray = {'a', 'b'};

How can you initialize an array of two characters to 'a' and 'b'? Selected Answers: A. Correct char[] charArray = {'a', 'b'}; B. Correct char[] charArray = {'a', 'b'}; Answers: A. Correct char[] charArray = new char[]{'a', 'b'}; B. Correct char[] charArray = {'a', 'b'}; C. char[2] charArray = {'a', 'b'}; D. char[] charArray = new char[2]; charArray = {'a', 'b'};

How many elements are in array double[] list = new double[5]? Answers: A. 6 B. 0 C. 4 D. 5

How many elements are in array double[] list = new double[5]? Selected Answer: D. Correct 5 Answers: A. 6 B. 0 C. 4 D. Correct 5

If a key is not in the list, the binarySearch method returns ________. Answers: A. -insertion point B. -(insertion point + 1) C. insertion point - 1 D. insertion point

If a key is not in the list, the binarySearch method returns ________. Selected Answer: B. Correct -(insertion point + 1) Answers: A. -insertion point B. Correct -(insertion point + 1) C. insertion point - 1 D. insertion point

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________. Answers: A. 2.0 B. 5.5 C. 3.5 D. 3.4 E. undefined

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________. Selected Answer: A. Correct 2.0 Answers: A. Correct 2.0 B. 5.5 C. 3.5 D. 3.4 E. undefined

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________. Answers: A. 0 B. 1 C. 2 D. 3 E. 4

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________. Selected Answer: Correct 3 Answers: A. 0 B. 1 C. 2 D. Correct 3 E. 4

Suppose a method p has the following heading: public static int[] p() What return statement may be used in p()? Answers: A. return {1, 2, 3}; B. return int[]{1, 2, 3}; C. return 1; D. return new int[]{1, 2, 3};

Suppose a method p has the following heading: public static int[] p() What return statement may be used in p()? Selected Answer: D. Correct return new int[]{1, 2, 3}; Answers: A. return {1, 2, 3}; B. return int[]{1, 2, 3}; C. return 1; D. Correct return new int[]{1, 2, 3};

Suppose a method p has the following heading: public static int[][] p() What return statement may be used in p()? Answers: A. return 1; B. return new int[]{1, 2, 3}; C. return new int[][]{{1, 2, 3}, {2, 4, 5}}; D. return {1, 2, 3}; E. return int[]{1, 2, 3};

Suppose a method p has the following heading: public static int[][] p() What return statement may be used in p()?Selected Answer: C. Correct return int[]{1, 2, 3}; Answers: A. return 1; B. return new int[]{1, 2, 3}; C. Correct return new int[][]{{1, 2, 3}, {2, 4, 5}}; D. return {1, 2, 3}; E. return int[]{1, 2, 3};

Suppose int i = 5, which of the following can be used as an index for array double[] t = new double[100]? Answers: A. (int)(Math.random() ** 100)) B. i C. i + 10 D. Math.random() * 100 E. i + 6.5

Suppose int i = 5, which of the following can be used as an index for array double[] t = new double[100]? Selected Answers: A. Correct (int)(Math.random() ** 100)) B. Correct i C. Correct i + 10 Answers: A. Correct (int)(Math.random() * 100)) B. Correct i C. Correct i + 10 D. Math.random() * 100 E. i + 6.5

Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect? Answers: A. int i = s1.length B. String s3 = s1 + s2 C. String s = new String("new string"); D. s1 >= s2 E. s1.charAt(0) = '5'

Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect? Selected Answers: A. Correct int i = s1.length D. Correct s1 >= s2 E. Correct s1.charAt(0) = '5' Answers: A. Correct int i = s1.length B. String s3 = s1 + s2 C. String s = new String("new string"); D. Correct s1 >= s2 E. Correct s1.charAt(0) = '5'

The JVM stores the array in an area of memory, called ________, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order. Answers: A. memory block B. stack C. dynamic memory D. heap

The JVM stores the array in an area of memory, called ________, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order. Selected Answer: D. Correct heap Answers: A. memory block B. stack C. dynamic memory D. Correct heap

The ________ method copies the sourceArray to the targetArray. Answers: A. System.arrayCopy(sourceArray, 0, targetArray, 0, sourceArray.length); B. System.copyarrays(sourceArray, 0, targetArray, 0, sourceArray.length); C. System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length); D. System.copyArrays(sourceArray, 0, targetArray, 0, sourceArray.length);

The ________ method copies the sourceArray to the targetArray. Selected Answer: C. Correct System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length); Answers: System.arrayCopy(sourceArray, 0, targetArray, 0, sourceArray.length); B. System.copyarrays(sourceArray, 0, targetArray, 0, sourceArray.length); C. Correct System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length); D. System.copyArrays(sourceArray, 0, targetArray, 0, sourceArray.length);

The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as ________. Answers: A. information hiding B. method hiding C. encapsulation D. simplifying method

The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as ________. Selected Answers: A. Correct information hiding C. Correct encapsulation Answers: A. Correct information hiding B. method hiding C. Correct encapsulation D. simplifying method

What is displayed by the following code? String[] tokens = "A,B;C;D".split("[,;]"); for (int i = 0; i < tokens.length; i++) System.out.print(tokens[i] + " "); Answers: A. A B C D B. B;C;D C. A B;C;D D. A B C;D

What is displayed by the following code? String[] tokens = "A,B;C;D".split("[,;]"); for (int i = 0; i < tokens.length; i++) System.out.print(tokens[i] + " "); Answers: A. Correct A B C D B. B;C;D C. A B;C;D D. A B C;D

What is displayed by the following statement? System.out.println("Java is neat".replaceAll("is", "AAA")); Answers: A. Java AAAneat B. JavaAAAneat C. JavaAAA neat D. Java AAA neat

What is displayed by the following statement? System.out.println("Java is neat".replaceAll("is", "AAA")); Selected Answer: D. Correct Java AAA neat Answers: A. Java AAAneat B. JavaAAAneat C. JavaAAA neat D. Correct Java AAA neat

What is k after the following block executes? { int k = 2; nPrint("A message", k); } System.out.println(k); A. 0 B. 1 C. 2 D. k is not defined outside the block. So, the program has a compile error

What is k after the following block executes? { int k = 2; nPrint("A message", k); } System.out.println(k); A. 0 B. 1 C. 2 Correct D. k is not defined outside the block. So, the program has a compile error

What is output of the following code: public class Test { public static void main(String[] args) { int[] x = {120, 200, 016}; for (int i = 0; i < x.length; i++) System.out.print(x[i] + " "); Answers: } } A. 120 200 14 B. 120 200 20 C. 120 200 16 D. 016 is a compile error. It should be written as 16.

What is output of the following code: public class Test { public static void main(String[] args) { int[] x = {120, 200, 016}; for (int i = 0; i < x.length; i++) System.out.print(x[i] + " "); } } Selected Answer: A Correct 120 200 14 Answers: A. Correct 120 200 14 B. 120 200 20 C. 120 200 16 D. 016 is a compile error. It should be written as 16.

What is the index variable for the element at the first row and first column in array a? Answers: A. a[0][0] B. a[1][1] C. a[1][0] D. a[0][1]

What is the index variable for the element at the first row and first column in array a? Selected Answer: A. Correct a[0][0] Answers: A. Correct a[0][0] B. a[1][1] C. a[1][0] D. a[0][1]

What is the output of the following code? public class Test { public static void main(String[] args) { int[][][] data = {{{1, 2}, {3, 4}}, 5, 6}, {7, 8}}}; System.out.print(ttt(data[0])); } public static int ttt(int[][] m) { int v = m[0][0]; for (int i = 0; i < m.length; o++) for (int j = 0; j < m[1].length; j++) if (v < m[i][j]) v = m[i][j]; return v; } } Answers: A. 1 B. 2 C. 4 D. 5 E. 6

What is the output of the following code? public class Test { public static void main(String[] args) { int[][][] data = {{{1, 2}, {3, 4}}, 5, 6}, {7, 8}}}; System.out.print(ttt(data[0])); } public static int ttt(int[][] m) { int v = m[0][0]; for (int i = 0; i < m.length; o++) for (int j = 0; j < m[1].length; j++) if (v < m[i][j]) v = m[i][j]; return v; } } Answers: A. 1 B. 2 C. Correct 4 D. 5 E. 6

Which of the following statements convert a double value d into a string s? Answers: A. s = new Double(d).stringOf(); B. s = (new Double(d)).toString(); C. s = String.stringOf(d); D. s = d + ""; E. s = d;

Which of the following statements convert a double value d into a string s? Selected Answers: B. Correct s = (new Double(d)).toString(); D. Correct s = d + ""; Answers: A. s = new Double(d).stringOf(); B. Correct s = (new Double(d)).toString(); C. s = String.stringOf(d); D. Correct s = d + ""; E. s = d;

You should fill in the blank in the following code with ______________. public class Test { public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5)); } public static _________ getGrade(double score) { if (score >= 90.0) return 'A'; else if (score >= 80.0) return 'B'; else if (score >= 70.0) return 'C'; else if (score >= 60.0) return 'D'; else return 'F'; } } A. int B. double C. boolean D. char E. void

You should fill in the blank in the following code with ______________. public class Test { public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5)); } public static _________ getGrade(double score) { if (score >= 90.0) return 'A'; else if (score >= 80.0) return 'B'; else if (score >= 70.0) return 'C'; else if (score >= 60.0) return 'D'; else return 'F'; } } A. int B. double C. boolean Correct D. char E. void

________ returns a string. Answers: A. String.valueOf(123) B. String.valueOf(new char[]{'a', 'b', 'c'}) C. String.valueOf(false) D. String.valueOf(12.53)

________ returns a string. Selected Answers: A. Correct String.valueOf(123) B. Correct String.valueOf(new char[]{'a', 'b', 'c'}) C. Correct String.valueOf(false) D. Correct String.valueOf(12.53) Answers: A. Correct String.valueOf(123) B. Correct String.valueOf(new char[]{'a', 'b', 'c'}) C. Correct String.valueOf(false) D. Correct String.valueOf(12.53)

(for-each loop) Analyze the following code: public class Test { public static void main(String[] args) { double[] x = {2.5, 3, 4}; for (double value: x) System.out.print(value + " "); } } Answers: Answers: A. The program displays 2.5, 3.0 4.0 B. The program displays 2.5 3.0 4.0 C. The program displays 2.5 3 4 D. The program displays 2.5, 3, 4 E. The program has a syntax error because value is undefined.

(for-each loop) Analyze the following code: public class Test { public static void main(String[] args) { double[] x = {2.5, 3, 4}; for (double value: x) System.out.print(value + " "); } } Selected Answer: B. Correct The program displays 2.5 3.0 4.0 Answers: A. The program displays 2.5, 3.0 4.0 B. Correct The program displays 2.5 3.0 4.0 C. The program displays 2.5 3 4 D. The program displays 2.5, 3, 4 E. The program has a syntax error because value is undefined.

(int)('a' + Math.random() * ('z' - 'a' + 1)) returns a random number ________. Answers: A. between 'a' and 'y' B. between (int)'a' and (int)'z' C. between 'a' and 'z' D. between 0 and (int)'z'

(int)('a' + Math.random() * ('z' - 'a' + 1)) returns a random number ________. Selected Answer: B. Correct between (int)'a' and (int)'z' Answers: A. between 'a' and 'y' B. Correct between (int)'a' and (int)'z' C. between 'a' and 'z' D. between 0 and (int)'z'

(int)(Math.random() * (65535 + 1)) returns a random number ________. Answers: A. between 0 and 65535 B. between 1 and 65535 C. between 1 and 65536 D. between 0 and 65536

(int)(Math.random() * (65535 + 1)) returns a random number ________. SeSelected Answer: A. Correct between 0 and 65535 Answers: A. Correct between 0 and 65535 B. between 1 and 65535 C. between 1 and 65536 D. between 0 and 65536

0.19 What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = "Welcome to Java!"; String s2 = s1; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } A. s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects

0.19 What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = "Welcome to Java!"; String s2 = s1; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } A. Correct s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects

6.18 What is output of the following code: public class Test { public static void main(String[] args) { int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < list.length; i++) list[i] = list[i - 1]; for (int i = 0; i < list.length; i++) System.out.print(list[i] + " "); } } Answers: A. 1 2 3 4 5 6 B. 2 3 4 5 6 6 C. 2 3 4 5 6 1 D. 1 1 1 1 1 1

6.18 What is output of the following code: public class Test { public static void main(String[] args) { int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < list.length; i++) list[i] = list[i - 1]; for (int i = 0; i < list.length; i++) System.out.print(list[i] + " "); } } Selected Answers: D. Correct 1 1 1 1 1 1 Answers: A. 1 2 3 4 5 6 B. 2 3 4 5 6 6 C. 2 3 4 5 6 1 D. Correct 1 1 1 1 1 1

Analyze the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < x.length; i++) System.out.print(x[i] + " "); } } Answers: A. The program displays 0 0 B. The program displays 0 0 0 0 C. The program displays 1 2 3 4 D. The program displays 0 0 3 4

A. Correct The program displays 0 0

Do the following two programs produce the same result? Program I: public class Test { public static void main(String[] args) { int[] list = {1, 2, 3, 4, 5}; reverse(list); for (int i = 0; i < list.length; i++) System.out.print(list[i] + " "); } public static void reverse(int[] list) { int[] newList = new int[list.length]; for (int i = 0; i < list.length; i++) newList[i] = list[list.length - 1 - i]; list = newList; } } Program II: public class Test { public static void main(String[] args) { int[] oldList = {1, 2, 3, 4, 5}; reverse(oldList); for (int i = 0; i < oldList.length; i++) System.out.print(oldList[i] + " "); } public static void reverse(int[] list) { int[] newList = new int[list.length]; for (int i = 0; i < list.length; i++) newList[i] = list[list.length - 1 - i]; list = newList; } } A. Yes B. No

A. Correct Yes

All Java applications must have a method ________. S Answers: A. public static main(String[] args) B. public static Main(String args[]) C. public static Main(String[] args) D. public static void main(String[] args) E. public void main(String[] args)

All Java applications must have a method ________. Selected Answer: D. Correct public static void main(String[] args) Answers: A. public static main(String[] args) B. public static Main(String args[]) C. public static Main(String[] args) D. Correct public static void main(String[] args) E. public void main(String[] args)

Analyze the following code. public class Test { public static void main(String[] args) { System.out.println(m(2)); } public static int m(int num) { return num; } public static void m(int num) { System.out.println(num); } } A. The program has a compile error because the two methods m have the same signature. B. The program has a compile error because the second m method is defined, but not invoked in the main method. C. The program runs and prints 2 once. D. The program runs and prints 2 twice

Analyze the following code. public class Test { public static void main(String[] args) { System.out.println(m(2)); } public static int m(int num) { return num; } public static void m(int num) { System.out.println(num); } } Correct A. The program has a compile error because the two methods m have the same signature. B. The program has a compile error because the second m method is defined, but not invoked in the main method. C. The program runs and prints 2 once. D. The program runs and prints 2 twice

Analyze the following code: public class Test { public static void main(String[] args) { boolean[][] x = new boolean[3][]; x[0] = new boolean[1]; x[1] = new boolean[2]; x[2] = new boolean[3]; System.out.println("x[2][2] is " + x[2][2]); } } Answers: A. The program has a runtime error because x[2][2] is null. B. The program runs and displays x[2][2] is null. C. The program runs and displays x[2][2] is true. D. The program has a compile error because new boolean[3][] is wrong. E. The program runs and displays x[2][2] is false.

Analyze the following code: public class Test { public static void main(String[] args) { boolean[][] x = new boolean[3][]; x[0] = new boolean[1]; x[1] = new boolean[2]; x[2] = new boolean[3]; System.out.println("x[2][2] is " + x[2][2]); } } Answer: Correct The program runs and displays x[2][2] is false. Answers: A. The program has a runtime error because x[2][2] is null. B. The program runs and displays x[2][2] is null. C. The program runs and displays x[2][2] is true. D. The program has a compile error because new boolean[3][] is wrong. E. Correct The program runs and displays x[2][2] is false.

Analyze the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); } } A. The program displays 1 2 3 4 B. The program displays 0 0 C. The program displays 0 0 3 4 D. The program displays 0 0 0 0

Analyze the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); } } Selected Answer: A. Correct The program displays 1 2 3 4 Answers: A. Correct The program displays 1 2 3 4 B. The program displays 0 0 C. The program displays 0 0 3 4 D. The program displays 0 0 0 0

Arguments to methods always appear within ________. Answers: A. quotation marks B. parentheses C. brackets D. curly braces

Arguments to methods always appear within ________. Selected Answer: B. Correct parentheses Answers: A. quotation marks B. Correct parentheses C. brackets D. curly braces

The following code: class Test { public static void main(String[] args) { String s; System.out.println("s is " + s) } Answers: A. The program has a runtime error because s is not initialized, but it is referenced in the println statement. B. The program has a compile error because s is not initialized, but it is referenced in the println statement. C. The program compiles and runs fine. D. The program has a runtime error because s is null in the println statement.

The following code: class Test { public static void main(String[] args) { String s; System.out.println("s is " + s) } Selected Answer: B. Correct The program has a compile error because s is not initialized, but it is referenced in the println statement. Answers: A. The program has a runtime error because s is not initialized, but it is referenced in the println statement. B. Correct The program has a compile error because s is not initialized, but it is referenced in the println statement. C. The program compiles and runs fine. D. The program has a runtime error because s is null in the println statement.

The following program displays __________. public class Test { public static void main(String[] args) { String s = "Java"; StringBuilder builder = new StringBuilder(s); change(builder); System.out.println(builder); } private static void change(StringBuilder builder) { builder.append(" and HTML"); } } Answers: A. Java B. Java and HTML C. and HTML D. nothing is displayed

The following program displays __________. public class Test { public static void main(String[] args) { String s = "Java"; StringBuilder builder = new StringBuilder(s); change(builder); System.out.println(builder); } private static void change(StringBuilder builder) { builder.append(" and HTML"); } } Answers: A. Java B. Correct Java and HTML C. and HTML D. nothing is displayed

The reverse method is defined in the textbook. What is list1 after executing the following statements? int[] list1 = {1, 2, 3, 4, 5, 6}; list1 = reverse(list1); Answers: A. list1 is 0 0 0 0 0 0 B. list1 is 1 2 3 4 5 6 C. list1 is 6 5 4 3 2 1 D. list1 is 6 6 6 6 6 6

The reverse method is defined in the textbook. What is list1 after executing the following statements? int[] list1 = {1, 2, 3, 4, 5, 6}; list1 = reverse(list1); Selected Answer: C. Correct list1 is 6 5 4 3 2 1 Answers: A. list1 is 0 0 0 0 0 0 B. list1 is 1 2 3 4 5 6 C. Correct list1 is 6 5 4 3 2 1 D. list1 is 6 6 6 6 6 6

The reverse method is defined in this section. What is list1 after executing the following statements? int[] list1 = {1, 2, 3, 4, 5, 6}; int[] list2 = reverse(list1); Answers: A. list1 is 6 6 6 6 6 6 B. list1 is 0 0 0 0 0 0 C. list1 is 6 5 4 3 2 1 D. list1 is 1 2 3 4 5 6

The reverse method is defined in this section. What is list1 after executing the following statements? int[] list1 = {1, 2, 3, 4, 5, 6}; int[] list2 = reverse(list1); Selected Answer: D. Correct list1 is 1 2 3 4 5 6 Answers: A. list1 is 6 6 6 6 6 6 B. list1 is 0 0 0 0 0 0 C. list1 is 6 5 4 3 2 1 D. Correct list1 is 1 2 3 4 5 6

The signature of a method consists of ________. Answers: A. method name and parameter list B. method name C. return type, method name, and parameter list D. parameter list

The signature of a method consists of ________. Selected Answer: A. Correct method name and parameter list Answers: A. Correct method name and parameter list B. method name C. return type, method name, and parameter list D. parameter list

To create an instance of BigDecimal for 454.45, use ________. Answers: A. new BigDecimal("454.45"); B. new BigInteger(454.45); C. BigInteger("454.45"); D. BigInteger(454.45);

To create an instance of BigDecimal for 454.45, use ________. Selected Answer: A. Correct new BigDecimal("454.45"); Answers: Answers: A. Correct new BigDecimal("454.45"); B. new BigInteger(454.45); C. BigInteger("454.45"); D. BigInteger(454.45);

Use the selectionSort method presented in this section to answer this question. What is list1 after executing the following statements? double[] list1 = {3.1, 3.1, 2.5, 6.4}; selectionSort(list1); Answers: A. list1 is 6.4, 3.1, 3.1, 2.5 B. list1 is 2.5 3.1, 3.1, 6.4 C. list1 is 3.1, 2.5, 3.1, 6.4 D. list1 is 3.1, 3.1, 2.5, 6.4

Use the selectionSort method presented in this section to answer this question. What is list1 after executing the following statements? double[] list1 = {3.1, 3.1, 2.5, 6.4}; selectionSort(list1); Selected Answer: B. Correct list1 is 2.5 3.1, 3.1, 6.4 Answers: : A. list1 is 6.4, 3.1, 3.1, 2.5 B. Correct list1 is 2.5 3.1, 3.1, 6.4 C. list1 is 3.1, 2.5, 3.1, 6.4 D. list1 is 3.1, 3.1, 2.5, 6.4

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = s1.toUpperCase(); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else if (s1.equals(s2)) System.out.println("s1 and s2 have the same contents"); else System.out.println("s1 and s2 have different contents"); } } Answers: A. s1 and s2 reference to the same String object B. s1 and s2 have the same contents C. s1 and s2 have different contents

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = s1.toUpperCase(); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else if (s1.equals(s2)) System.out.println("s1 and s2 have the same contents"); else System.out.println("s1 and s2 have different contents"); } } Answers: A. s1 and s2 reference to the same String object B. s1 and s2 have the same contents C. Correct s1 and s2 have different contents

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java"); String s2 = s1; s1 += "and Welcome to HTML"; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } A. s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java"); String s2 = s1; s1 += "and Welcome to HTML"; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } A. s1 and s2 reference to the same String object B. Correct s1 and s2 reference to different String objects

What is the output of the following program? public class Test { public static void main(String[] args) { int[][]values = {{3, 4, 5, 1}, {33, 6, 1, 2}}; for (int row = 0; row < values.length; row++) { System.out.print(m(values[row]) +" "); } } public static int m(int[] list) { int v = list[0]; for (int i = 1; i < list.length i++} if (v < list[i]) return v; }} Answers: A. 5 6 B. 5 33 C. 33 5 D. 1 1 E. 3 33

What is the output of the following program? public class Test { public static void main(String[] args) { int[][]values = {{3, 4, 5, 1}m {33, 6, 1, 2}}; for (int row = 0; row < values.length; row++) { System.out.print(m(values[row]) +" "); } } public static int m(int[] list) { int v = list[0]; for (int i = 1; i < list.length i++} if (v < list[i]) return v; }} Answers: A. 5 6 B. Correct 5 33 C. 33 5 D. 1 1 E. 3 33

What is the output of the following program? public class Test { public static void main(String[]args) { int[][]values = {{3,4,5,1}, {33,6,1,2}}; int v = values[0][0]; for(int row=0; row<values.length; row++) for(int column = 0; column<values[row].length; column++) if(v<values[row][column]) v=values[row][column]; System.out.print(v); }} Answers: A. 3 B. 33 C. 1 D. 5 E. 6

What is the output of the following program? public class Test { public static void main(String[]args) { int[][]values = {{3,4,5,1}, {33,6,1,2}}; int v = values[0][0]; for(int row=0; row<values.length; row++) for(int column = 0; column<values[row].length; column++) if(v<values[row][column]) v=values[row][column]; System.out.print(v); }} Answers: A. 3 B. 33 C. Correct 1 D. 5 E. 6

What is the representation of the third element in an array called a? Answers: A. a[3] B. a[2] C. a(2) D. a(3)

What is the representation of the third element in an array called a? Selected Answer: B. Correct a[2] Answers: A. a[3] B. Correct a[2] C. a(2) D. a(3)

When you create an array using the following statement, the element values are automatically initialized to 0. int[][] matrix = new int[5][5]; Answers: A. True B. False

When you create an array using the following statement, the element values are automatically initialized to 0. int[][] matrix = new int[5][5]; Selected Answer: A. Correct True B. False

When you pass an array to a method, the method receives ________. Answers: A. the reference of the array B. the length of the array C. a copy of the array D. a copy of the first element

When you pass an array to a method, the method receives ________. Selected Answer: A. Correct the reference of the array Answers: A. Correct the reference of the array B. the length of the array C. a copy of the array D. a copy of the first element

When you return an array from a method, the method returns ________. Answers: A. a copy of the array B. a copy of the first element C. the reference of the array D. the length of the array

When you return an array from a method, the method returns ________. Selected Answer: Correct the reference of the array Answers: A. a copy of the array B. a copy of the first element C. Correct the reference of the array D. the length of the array

Which of the following classes are immutable? Answers: A. Integer B. BigInteger C. String D. BigDecimal E. Double

Which of the following classes are immutable? Selected Answers: A. Correct Integer B. Correct BigInteger C. Correct String D. Correct BigDecimal E. Correct Double Answers: A. Correct Integer B. Correct BigInteger C. Correct String D. Correct BigDecimal E. Correct Double

Which of the following should be defined as a void method? Answers: A. Write a method that checks whether a number is from 1 to 100. B. Write a method that converts an uppercase letter to lowercase. C. Write a method that returns a random integer from 1 to 100. D. Write a method that prints integers from 1 to 100.

Which of the following should be defined as a void method? Selected Answer: D. Correct Write a method that prints integers from 1 to 100. Answers: A. Write a method that checks whether a number is from 1 to 100. B. Write a method that converts an uppercase letter to lowercase. C. Write a method that returns a random integer from 1 to 100. D. Correct Write a method that prints integers from 1 to 100.

Which of the following statements are correct to invoke the printMax method in Listing 7.5 in the textbook? Answers: A. printMax(1.0, 2.0, 2.0, 1.0, 4.0); B. printMax(new int[]{1, 2, 3}); C. printMax(1, 2, 2, 1, 4); D. printMax(new double[]{1, 2, 3});

Which of the following statements are correct to invoke the printMax method in Listing 7.5 in the textbook? Selected Answers: A. Correct printMax(1.0, 2.0, 2.0, 1.0, 4.0); C. Correct printMax(1, 2, 2, 1, 4); D. Correct printMax(new double[]{1, 2, 3}); Answers: A. Correct printMax(1.0, 2.0, 2.0, 1.0, 4.0); B. printMax(new int[]{1, 2, 3}); C. Correct printMax(1, 2, 2, 1, 4); D. Correct printMax(new double[]{1, 2, 3});


संबंधित स्टडी सेट्स

Chapter5 Microeconomics Elasticity

View Set

AQR B Unit 2 Lesson 3 Making Monthly Payments Quick Check

View Set

ACC 232 Nowland Exam 1 MC Practice

View Set

Business Finance Exam 3 Chapters 10-12

View Set

Chapter 14 - PrepU - Before Conception

View Set

Ch. 21- Somatic Symptom Illnesses

View Set