CompSci StudyPacket S 23
CompSci StudyPacket S 23
2023 STATE
MAY 2023
General Directions (Please read carefully!)
1. DO NOT OPEN THE EXAM UNTIL TOLD TO DO SO.
2. There are 40 questions on this contest exam. You will have 45 minutes to complete this contest.
3. All answers must be legibly written on the answer sheet provided. Indicate your answers in the
appropriate blanks provided on the answer sheet. Clean erasures are necessary for accurate grading.
4. You may write on the test packet or any additional scratch paper provided by the contest director, but
NOT on the answer sheet, which is reserved for answers only.
5. All questions have ONE and only ONE correct answer. There is a 2-point penalty for all incorrect answers.
6. Tests may not be turned in until 45 minutes have elapsed. If you finish the test before the end of the
allotted time, remain at your seat and retain your test until told to do otherwise. You may use this time to
check your answers.
7. If you are in the process of actually writing an answer when the signal to stop is given, you may finish
writing that answer.
8. All provided code segments are intended to be syntactically correct, unless otherwise stated. You may
also assume that any undefined variables are defined as used.
9. A reference to many commonly used Java classes is provided with the test, and you may use this
reference sheet during the contest. AFTER THE CONTEST BEGINS, you may detach the reference sheet
from the test booklet if you wish.
10. Assume that any necessary import statements for standard Java SE packages and classes (e.g.,
java.util, System, etc.) are included in any programs or code segments that refer to methods from
these classes and packages.
11. NO CALCULATORS of any kind may be used during this contest.
Scoring
1. Correct answers will receive 6 points.
2. Incorrect answers will lose 2 points.
3. Unanswered questions will neither receive nor lose any points.
4. In the event of a tie, the student with the highest percentage of attempted questions correct shall win
the tie.
Interface BiFunction<T,U,R>
R apply(T t, U u)
Interface BiPredicate<T,U>
boolean test(T t, U u)
Interface Consumer<T>
void accept(T t)
Interface Function<T,R>
R apply(T t)
Interface Predicate<T>
boolean test(T t)
Interface Supplier<T>
T get()
Question 1i
If the values of the five numbers were converted to a common base and sorted, which one would be in the middle - larger than two
numbers and smaller than the other two?
A) 110111012 B) 2658 C) 18010 D) B916 E) 33334
Question 2uesti
What is the output of the code segment to the right? out.print(23 + 37 / 7 % 2 - 24 % 5);
A) -3 B) 20 C) 21 D) 53 E) 9
Question 3 int May = 68;
What is the output of the code segment to the right? double State = May / 5;
A) 68-13.60-c String St ="%d-%.2f-%c";
B) 68-13.00-c out.printf(St, May, State, May);
C) 68-13.60-D
D) 68-13.00-D
E) 54.40-D
Question 5 int A = 4;
What is the output of the code segment to the right? int B = 7;
int C = 2;
A) true
boolean D = (A>C) && (B<A);
B) false boolean E = (A + B == 10)||(A >= C*2);
boolean F = D ^ E;
out.print(F);
Question 6 int H = 5;
What is the output of the code segment to the right? int J = (int)(Math.pow(H,3));
A) 11 B) 12 C) 13 D) 14 E) 15 int L = (int)(Math.sqrt(J));
out.print(L);
Question 12 int G = 0;
What is the output of the code segment to the right? for (int x=10; x<=50; x++)
A) 201 B) 209 C) 219 D) 221 E) 229 G += (int)(Math.sqrt(x)+0.5);
out.print(G);
Question 14
What is the output of the code segment shown on the right? int K = Integer.SIZE;
int L = Double.SIZE;
A) 2 B) 4 C) 6 D) 8 E) 12
int M = Byte.SIZE;
out.println(K / M + L / K);
Question 16
What is the output of the code segment shown on the right? int N = 25;
int z=0;
A) 100 B) 121 C) 144 D) 169 E) 625
for(int x=1; x<=N; x+=2)
z +=x;
out.print(z);
}
//////////////////////////////////
// Client code
Rockford Jim = new Rockford(10);
System.out.println(Jim.getOne()); //Line 1
System.out.println(Jim.getTwo()); //Line 2
System.out.println(Jim.getThree());//Line 3
Question 39
Evaluate the prefix expression to the right. Write the value in the
blank reserved for #39. + / * 3 4 - 17 * 5 3 / + 6 6 3
Note: Correct responses are based on Java SE Development Kit 17 (JDK 17) from Oracle, Inc. All provided code segments are intended to be syntactically correct,
unless otherwise stated (e.g., "error" is an answer choice) and any necessary Java SE 17 Standard Packages have been imported. Ignore any typographical errors and
assume any undefined variables are defined as used.
6. A int H = 5;
int J = (int)(Math.pow(H,3)); J = 125
int L = (int)(Math.sqrt(J)); L = (int)(11.18) = 11
out.print(L);
7. E int A = 10;
int B = 25;
int Z = A + B % A * A - B / A;
10 + 25 % 10 * 10 - 25 / 10
10 + 5 * 10 - 25 / 10
10 + 50 - 25 / 10
10 + 50 - 2
60 - 2 = 58
if (AA % CC == 5) true!!!
AA += CC; AA is now 45
else if (AA > 100)
AA -= 100;
out.print(AA);
out.println(Alpha.getC()); // Line 11
class One does not have a getC() method
out.println(Beta.getC()); // Line 12
This error occurs at compilation time, class One does not contain a getC() method
out.println(Gamma.A); // Line 14
A is a private instance variable which cannot be accessed in this manor.
out.println(Gamma.E); // Line 16
E is a private instance variable which cannot be accessed in this manor.
36. B if(A==B) N++; true because A and B now represent the same object.
if(B==C) N++; false
if(C==D) N++; false
if(E==A) N++; false
if (A.equals(C)) N++; true because A now contains the String "Banana"
if (B.equals(D)) N++; false
if (C.equals(E)) N++; false
if (D.equals(B)) N++; false
0 0 0 0 0
0 1 2 3 4
0 2 5 8 11
0 3 8 14 20
0 4 11 20 30
Box[4][3] = 20 (and so does Box[3][4]) See the pattern emerging?
38. A 16 ^ 28 = 10000 ^ 11100 = 01100
12 ^ 27 = 01100 ^ 11011 = 10111
23 ^ 26 = 10111 ^ 11010 = 01101
13 ^ 25 = 01101 ^ 11001 = 10100
20 ^ 24 = 10100 ^ 11000 = 01100
12 ^ 23 = 01100 ^ 10111 = 11011
27 ^ 22 = 11011 ^ 10110 = 01101
16 ^ 21 = 01101 ^ 10101 = 11000 = 24
39. 10 + / * 3 4 - 17 * 5 3 / + 6 6 3
+ / * 3 4 - 17 * 5 3 / 12 3
+ / * 3 4 - 17 * 5 3 4
+ / * 3 4 - 17 15 4
+ / * 3 4 2 4
+ / 12 2 4
+ 6 4 = 10
40. 10 A truth table would be apropos
ABCD AB + CD (A + B) * (C + D)
0000 0 0 same 1
0001 0 0 same 2
0010 0 0 same 3
0011 1 0
0100 0 0 same 4
0101 0 1
0110 0 1
0111 1 1 same 5
1000 0 0 same 6
1001 0 1
1010 0 1
1011 1 1 same 7
1100 1 0
1101 1 1 same 8
1110 1 1 same 9
1111 1 1 same 10