Professional Documents
Culture Documents
True (*)
False
3. Which of the following declares a one dimensional array named "score" of type int that can hold
9 values?
int score;
int[] score;
int[] score=new int[9]; (*)
int score=new int[9];
4. Which of the following declares and initializes a two dimensional array?
int[][] array={{1,1,1},{1,1,1},{1,1,1}}; (*)
int[] array={{1,1,1},{1,1,1},{1,1,1}};
int[][] array={1,1,1},{1,1,1},{1,1,1};
int[][] array={1,1,1,1,1,1,1,1,1};
5. Which of the following declares and initializes a one dimensional array named words of size 10
so that all entries can be Strings?
String words=new String[10];
char words=new char[10];
char[] words=new char[10];
String[] words=new String[10]; (*)
6.
222220
0 (*)
220
2
This code does not compile.
1286864
643432
262423242322
666666 (*)
This code does not compile.
8. Which of the following declares and initializes a two dimensional array named values with 2
rows and 3 columns where each element is a reference to an Object?
String[][] values={"apples","oranges","pears"};
String[][] values=new String[3][2];
Sectiunea 6
753
6
7766554433221
7531 (*)
This code does not compile.
12.
The following creates a reference in memory named y that can refer to five different integers
via an index. True or false? int[] y = new int[5];
True (*)
False
13. The following creates a reference in memory named z that can refer to seven different doubles
via an index. True or false? double z[] = new double[7];
True (*)
False
14. What is the output of the following segment of code if the command line arguments are "apples
oranges pears"?
apples
pears (*)
oranges
args
This code doesn't compile.
15. What is the output of the following segment of code if the command line arguments are "apples
oranges pears"?
0
1
2
3 (*)
This code does not compile.
16. What will be the content of array variable table after executing the following code?
Sectiunea 6
000
000
000
100
010
0 0 1 (*)
100
110
111
001
010
100
17.What is the output of the following segment of code?
1286864 (*)
643432
262423242322
666666
This code does not compile.
18. After execution of the following statement, which of the following are true?
int number[] = new int[5];
number[0] is undefined
number[4] is null
number[2] is 0 (*)
number.length() is 6
19. The following array declaration is valid. True or false?int x[] = int[10];
False (*)
True
Quiz 2 Sectiunea 6
1. Consider the following code snippet. What is printed?
String river = new String("Hudson"); System.out.println(river.length());
6 (*)
7
8
Hudson
river
2. Which of the following creates a String reference named str and instantiates it?
String str;
str="str";
String s="str";
String str=new String("str"); (*)
3. Declaring and instantiating a String is much like any other type of variable. However, once
instantiated, they are final and cannot be changed. True or false?
True (*)
False
4. Which of the following statements declares a String object called name?
String name; (*)
String name
Sectiunea 6
int name;
double name;
5. Suppose that s1 and s2 are two strings. Which of the statements or expressions are valid?
String s3 = s1 + s2; (*)
String s3 = s1 - s2;
s1 <= s2
s1.compareTo(s2); (*)
int m = s1.length(); (*)
6. Consider the following code snippet. What is printed?
PoliiPolii (*)
Polii
auaacauaac
auaac
ArrayIndexOutofBoundsException is thrown
"\\\\\"
\"\\\\\"
"\\" (*)
""\\"
""\"
""\
"\\\"
8. What will the following code segment output?
" (*)
"""\
""
""\
""
9. The following program prints "Equal". True or false?
True (*)
False
String char;
11. Given the code, which of the following would equate to true?
String s1 = "yes";
String s2 = "yes";
String s3 = new String(s1);
s1 == s2 (*)
s1 = s2
s3 == s1
s1.equals(s2) (*)
s3.equals(s1) (*)
12. The String methods equals and compareTo perform the exact same function. True or false?
True
False (*)
13. The == operator can be used to compare two String objects. The result is always true if the two
strings are identical. True or false?
True
False (*)
14. The following program prints "Equal". True or false?
True
False (*)
15. Given the code below, which of the following calls are valid?
String s = new String("abc");
s.trim() (*)
s.replace('a', 'A') (*)
s.substring(2) (*)
s.toUpperCase() (*)
s.setCharAt(1,'A')
16. Consider the following code snippet. What is printed?
String ocean = new String("Atlantic Ocean"); System.out.println(ocean.indexOf('a'));
0
2
3 (*)
11
12
17. Consider the following code snippet. What is printed?
55555
87668 (*)
AtlanticPacificIndianArcticSouthern
The code does not compile.
An ArrayIndexOutofBoundsException is thrown.
Sectiunea 6
55555
87658
AtlanticPacificIndianArcticSouthern
The code does not compile.
An ArrayIndexOutofBoundsException is thrown. (*)
19.How would you use the ternary operator to rewrite this if statement?
if (skillLevel > 5)
numberOfEnemies = 10;
else
numberOfEnemies = 5;
Quiz 3 Sectiunea 6
1. Which of the following would give you an array index out of bounds exception?
Misspelling a variable name somewhere in your code.
Refering to an element of an array that is at an index less than the length of the array minus
one.
Using a single equal symbol to compare the value of two integers.
Refering to an element of an array that is at an index greater than the length of that array
minus one. (*)
Unintentionally placing a semicolon directly after initializing a for loop.
2. What exception message indicates that a variable may have been mispelled somewhere in the
program?
variableName cannot be resolved to a variable (*)
Sectiunea 6
The program will calculate that each employee will receive zero dollars because there are
zero employees.
An exception will occur because it is not possible to divide by zero. (*)
The programmers will have proven their worth in the company because without them the
company wrote faulty code.
Sectiunea 6