Professional Documents
Culture Documents
HKICO 2019-2020 - Heat - Java
HKICO 2019-2020 - Heat - Java
COMPUTATIONAL OLYMPIAD
HEAT ROUND 2019 - 2020 (HONG KONG REGION)
Java
Time allowed: 60 minutes
Question Paper
Instructions to Contestants:
1. Each contestant should have ONE Question-Answer Book which CANNOT be taken away.
2. There are a total of 20 questions in this Question-Answer Book. Two points for correct answers. No points
for incorrect answers. ONE penalty point will be deducted for incorrect answers.
3. All answers should be written on ANSWER SHEET.
4. During the contest, NO calculators can be used for PRIMARY GROUP but calculators can be used for
SECONDARY GROUP.
5. All figures in the paper are not necessarily drawn to scale.
6. This Question-Answer Book will be collected at the end of the contest.
1. Java source code is compiled to byte code, which is then executed by the JVM. What is Java?
A. Compiled language
B. Interpreted language
C. Markup Language
D. Machine language
E. None of the above
A. java.util.Scanner
B. java.io.PrintStream
C. java.io.Console
D. None of the above
E. All of the above
A.
B.
C.
D.
E. None of the above
Consider the following code for question 5 to 7:
5. Argument list „args[]‟ of method MyClass.main is supplied with values given at?
A. Compile time
B. Runtime
C. First at compile time but can be overridden at runtime
D. Runtime but would be overridden if already defined at compile time
E. None of the above
6. In what condition the identifier public of class MyClass is necessary for the source code file MyClass.java
to compile?
7. What is the expected output (in console) when the compiled code is executed with the command
`java MyClass a=20 b=30`?
A. 50
B. 35
C. Sum of a and b = 35
D. Sum of a and b = 2030
E. None of the above
8. What is the expected output of the following code?
A. 25
B. 50
C. 75
D. Compile Error
E. None of the above
9. What is the expected output of the following code? (You can refer to the ASCII table provided in
APPENDIX)
A. 65
B. A
C. Compile Error
D. Runtime Error
E. None of the above
A.
B.
C.
D. All of the Above
E. None of the above
11. Which of the provided option(s) could be filled in the following code (indicated with comment) so that the
code could compile without error?
A.
B.
C.
D. All of the above
E. None of the above
12. What is the expected output when the following code is executed with terminal command java Main a=2
c=3?
2
3
A.
2
3
B.
a=2
a=3
C.
a=2
a=3
D.
E. None of the above
Refer to the following code for question 13 and 14:
13. What is the expected output of the code executed with the terminal command java Main 2 3?
A. 5
B. 23
C. 255
D. 333
E. None of the above
14. Would the program compile without error if the command is changed to java Main a=2 b=3 c=4?
15. A student writes a program calculating Fibonacci sequence but the program failed to compile. Which of the
following is/are valid explanation(s)?
16. After fixing the code, the student wants to print the whole sequence till the n-th term instead of n-th term
only. He / She wants to keep using recursion, his / her friend tells him/she that recurson is impossible, for-
loop should be used instead. Which of the following is a correct statement?
A. The friend is correct, recursion is not plausible when output of intermediate terms is necessary.
B. The friend is not correct, only recursion is plausible in this case.
C. The friend is not correct, for-loop and recursion are both applicable.
D. For-loop and recursion should never be used in any case, because of their low complexity.
E. None of the above
A. true
B. false, because integer 5 does not equal to a string “5”
C. false, because object reference should not be compared directly with „==‟
D. Compile error because string “5” is not an integer
E. None of the above
18. Given the following code:
~ 全卷完 ~
~ End of Paper ~
APPENDIX I: ASCII TABLE