FinalExamB example

FinalExamB example - CMPS 12A Winter 2002 Final Exam B...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CMPS 12A - Winter 2002 Final Exam B March 16, 2002 Name:__________________________________________ID:____________________________ This is a closed note, closed book exam. Any place where you are asked to write code, you must declare all variables that you use. However, I just want code fragments, you must not write extra code such as a class specification or extraneous print statements. Section I: 20 multiple choice questions [5 points each] For each of the following questions, write the letter of the best answer to the right of the question including, where appropriate, “All” for “All of the above” or “None” for “None of the above”. 1. Given a = 5 and b = 7, what does this code print out if (b < a) System.out.println("1"); else if (a + 2 == b) System.out.println("2"); else if (a < b) System.out.println("3"); a. 1 b. 2 c. 3 d. both 2 and 3 e. nothing 2. The purpose of testing is to make sure your program: a. Does what it is supposed to do b. Doesn't do what it is not supposed to do c. Does what it used to do 3. Which are valid literals a. 5L, 3.7, '\n', "(&(#@" b. 23, 4.5, -0.01, 'abc', "12897a*&)U" c. 5, 4-5, 0.0000004, ';', "Hello" 4. Which list of operators is listed in order of precedence a. +, *, /, = b. ++, *, +, = c. &&, *, +, % 5. Which of the following results in a = = 0 a. int a = 3/4; b. int a = 3.0/4.0; c. double a = 3/4; B All A - ‘abc’ and 4-5 are not valid literals, but 5L is B All
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 6. If a = 1 and b = 23, what does this expression print out if(!( (1+2*a == 3) && (b-23+a != 1) )) System.out.println("false"); else System.out.println("true"); a. true b. false c. nothing 7. Which are all Java keywords: a. int, double, for, array, and break b. continue, break, main, switch, and float c. char, boolean, final, static, and this 8. Method overloading is when you write a method a. That has too much code in it b. That has the same name and parameters as another method in the class c. That has the same name but different parameters than another method in the class 9. What is the value of the expression (3+4*5 - 4*5+3) a. 0 b. 12 c. 3 10. What does this code print out: int a = 'b'; switch(a) { case 'a': System.out.println('1'); case 'b': System.out.println('2'); case 'c': System.out.println('3'); } a. 1 b. 2 c. 3 d. both 2 and 3 e. nothing 11. char a = 'a'; a++; a is equal to: a. 'b' b. b c. error 12. The type of a variable specifies: a. its value b. its name c. the operations that are permitted on it C - array and main are not keywords C None - it print out 6 (= 3 + 20 - 20 + 3) D - no break state- ments A C B - the test is true, so false is printed out
Background image of page 2
3 13. Public vs. Private: a. Public methods can only access public data elements b. Private data elements are accessible by methods in the same package c. By default, all data elements are private 14. What does this (ugly) code print out: class Foo { Public static void main(String[] args) { int[] foo = {3, 5, 7}; if (foo[0] > foo[1]) swap(foo, 0, 1); if (foo[2] < foo[1]) swap(foo, 1, 2); if (foo[0] > foo[1]) swap(foo, 0, 1); System.out.println(foo[0] + " " + foo[1] + " " + foo[2]); } void swap(int[] a, int b, int c) { int temp = a[b]; a[b] = a[c]; a[c] = temp; }} a. 3 5 7 b. 7 5 3 c. 15 15. In for loops: a. The initialization expression is executed zero or more times b. The boolean expression is executed zero or more times c. The update expression is executed zero or more times 16. What does this print out: for(int i = 2; i < 100-i; i = i*i - i/2) System.out.print(i + " "); a. 2 4 8 16 32 b. 2 3 7.5 56.25 c. 2 3 7 42 17. Which is true?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/19/2012 for the course STAT 211 taught by Professor Parzen during the Spring '07 term at Texas A&M.

Page1 / 54

FinalExamB example - CMPS 12A Winter 2002 Final Exam B...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online