Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Student Name: Student ID: Time: 1 hour Computer Programming, I ECOM 2005 Khaleel I. Shaheen Fall 2017 Final Exam Question 1) Choose the correct answer: 1. consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line. a. Java API b. Java language specification c. Java IDE d. Java JDK 2. Which of the following statements is correct? a. Every line in a program must end with b. Every statement in a program must end with c. Every comment line must end with d. Every method must end with a semicolon. 3. is a software that interprets Java bytecode. a. Java virtual machine b. Java compiler c. Java debugger d. Java API 4. Which of the following lines is not a Java comment? (Choose Multiple) a. /** comment */ b. // comment c. -- comment d. /* comment */ e. ** comment ** 5. A block is enclosed inside. a. parentheses b. braces c. brackets d. quotes 6. Which of the following is a valid identifier? (Choose Multiple) a. $343 b. class c. 9X d. 8+9 e. radius 7. Which of the following assignment statements is incorrect? (Choose Multiple) a. i = 1 = j = 1 = k = 1; b. i = 1; j = 1; k = 1; c. i = j = k = 1; d. i == j == k == 1; 8. Which of these data types requires the most amount of memory? a. long b. int c. short d. byte 9. -24 % -5 is a. -1 b. -4 c. 4 d. 0 1
10. What is x after the following statements? int x = 2; int y = 1; x *= y + 1; a. x is 1. b. x is 2. c. x is 3. d. x is 4. 11. Which of the following expressions will not yield 0.5? a. 1.0 / 2 b. (double) (1 / 2) c. (double) 1 / 2 d. 1 / 2.0 12. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 13. A Java character is stored in. a. one byte b. two bytes c. three bytes d. four bytes 14. The Unicode of 'a' is 97. What is the Unicode for 'c'? a. 96 b. 97 c. 98 d. 99 15. '3' - '2' + 'm' / 'n' is. a. 0 b. 1 c. 2 d. 3 16. Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to. a. 66 b. B c. A1 d. error 17. In Java, the word true is. a. a Java keyword b. a Boolean literal c. same as value 1 d. same as value 18. Analyze the following code: boolean even = false; if (even = true) { System.out.println("It is even!"); a. The program has a compile error. b. The program has a runtime error. c. The program runs, but displays nothing. 19. Assume x = 4 and y = 5, Which of the following is true? 0 d. The program runs and displays "It is even!". a. x < 5 && y < 5 b. x < 5 y < 5 c. x > 5 && y > 5 d. x > 5 y > 5 2
20. Suppose x=10, y=10 what is x after evaluating the expression (y > 10) && (++x > 10). a. 9 b. 10 c. 11 d. other 21. In Java, the names of parameters and arguments must be the same. a. True b. False 22. In an infinite while loop, the loop condition is initially false, but after the first iteration, it is always true. a. True b. False 23. "abc".compareto("aba") returns. a. 1 b. 2 c. -1 d. -2 24. Assume int[][] x = {{1, 2, {3, 4, {5, 6, what are x.length and x[0].length? a. 3 and 2 b. 2 and 3 c. 3 and 3 d. 2 and 1 25. is a construct that defines objects of the same type. a. A class b. An object c. A method d. A data field 26. Which of the following statements are true? (choose multiple) a. Multiple constructors can be defined in a class. b. Constructors do not have a return type, not even void. c. Constructors must have the same name as the class itself. 27. Variables that are shared by every instance of a class are. d. Constructors are invoked using the new operator. a. public variables b. private variables c. instance variables d. static variables 28. A method that is associated with an individual object is called. a. static method b. class method c. instance method d. object method 29. is invoked to create an object. a. new operator b. constructor c. main method d. method with a return type 30. Exam Difficulty? a. b. c. Multiple Questions Answer Sheet: 1 2 3 4 5 6 7 8 9 10 D B A CE B AE AD A B D 11 12 13 14 15 16 17 18 19 20 B D B D B C B D B B 21 22 23 24 25 26 27 28 29 30 B B B A A ABCD D C B A, B, C 3
Question 2) Print the output for every code snippet below: Code int x = 3; int y = 4; switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1; System.out.println(y); char ch = 'b'; switch (ch) { case 'a': case 'b': case 'c': case 'd': boolean even = false; System.out.println( (even? "true" : "false") ); for (int i = 1; i <= 10; i++){ System.out.print(i + " "); i++; int[] mylist = {1, 2, 3, 4, 5, 6; for (int i = mylist.length - 2; i >= 0; i--){ mylist[i + 1] = mylist[i]; for (int e: mylist) System.out.print(e + " "); int[][] matrix = {{1, 2, 3, 4, {4, 5, 6, 7, {8, 9, 10, 11, {12, 13, 14, 15; for (int i = 0; i < 4; i++) System.out.print(matrix[i][1] + " "); class Foo { int i; static int s; public static void main(string[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); public Foo() { i++; s++; Good Luck Output 2 bbb false 1 3 5 7 9 1 1 2 3 4 5 2 5 9 13 f1.i is 1 f1.s is 1 f1.i is 1 f1.s is 2 f1.i is 1 f1.s is 3 4