Beruflich Dokumente
Kultur Dokumente
Version A
PART1 Multiple choice questions
50 bytes
1 KB (**)
1 MB
1 GB
1 TB
characters
integers
floating point numbers
references
all of the above (**)
1|Page
11010110 (**)
11010111
11010101
11011000
11010100
4. The highest (signed) positive integer that can be represented in n-bit twoscomplement binary is:
A.
B.
C.
D.
E.
n
n-1
2n-1-1 (**)
2n-1
2n-1
2|Page
-n
-n-1
-2n-1-1
-2n-1 (**)
-2n-1
6. What does the following Java code snippet print to standard output?
byte i = 127;
i++;
System.out.println(i);
A.
B.
C.
D.
E.
127
128
-127
-128 (**)
none of the above
3|Page
127 (**)
128
-127
-128
none of the above
4|Page
classes
objects
variables
methods
comments (**)
5|Page
11. Which Java class can read from the standard input?
A.
B.
C.
D.
E.
System
Scanner (**)
Math
String
Character
12. What does the following code snippet print to standard output?
final double PI=3.14159;
System.out.printf(%.3f\n, PI);
A.
B.
C.
D.
E.
3.141592653589793
3.14159
3.142 (**)
3.141
3.000
6|Page
int
int
int
int
int
i;
i =
i =
i =
i =
0;
0;
-0;
0.0; (**)
14. Which of the following statements allocates an array of 100 int values?
A.
B.
C.
D.
E.
int a[100];
int[] a = {100};
int[] a = new int[100]; (**)
int[] a = new int[]{100};
all of the above
7|Page
A.
B.
C.
D.
E.
if (a)
x = a;
x = a;
x = a;
x = a;
= c; else x = false;
= c; (**)
= c;
x = c; }
A.
B.
C.
D.
E.
statement
statement
statement
statement
statement
1;
2;
1; and statement 2; (**)
1; and statement 4;
1;and statement 2; and statement 4;
8|Page
infinitely many
2
3 (**)
4
5
18. The following incomplete code snippet is intended to compute the sum of all the
elements of the array.
public int sum(int[] array) {
int sum = 0;
int i = 0;
for (int elt : array) {
// missing loop body
}
return sum;
}
Which of the following loop bodies correctly computes the sum?
A.
B.
C.
D.
E.
sum +=
sum +=
sum +=
both a
both b
elt;
array[i++];
array[++i];
and b (**)
and c
9|Page
no longer usable
unable to be modified after it is initialized (**)
automatically initialized to zero
usable only in loops
initialized to null
"hello".charAt(0) == 'h'
"HELLO".toLowerCase() == "hello" (**)
"hello".indexOf('o') == 4
"HELLO".substring(2, 4).equals("LL")
hello == hello
10 | P a g e
ANSWER
int median(int[] array) {
int[] a = Arrays.copyOf(array);
Arrays.sort(a);
return a[(int)(a.length / 2)];
}
11 | P a g e
12 | P a g e