practicemult

# practicemult - Practice multiple choice exam questions....

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

Practice multiple choice exam questions. Question 1 (2 marks) Which of the following is an INVALID identifier? A Char B char C _char D _char_ E char\$ Question 2 (2 marks) What is the syntax problem with the following expression (a + 2b) / c / g A nothing B brackets needed around c C 2b should be 2 * b D You cannot have 2 divide operators in an expression E brackets needed around c / g Question 3 (2 marks) int sum = 0; for (int k = 1; k <= 5; k++) { int n = k; // STATEMENT GOES HERE } The above code fragment is intended to add the integers from 1 to 5 inclusive. Which of the following statements (replacing the comment in the code fragment) does NOT do this correctly? A sum = sum + n; B sum += n; C sum += n++; D sum += ++n; E sum += n--; Question 4 (2 marks) System.out.println (13 / 5 * 6 % 7); What is the output A 0 B 1

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

View Full Document
C 2 D 3 E none of the above Question 5 (2 marks) int sum = 0; int k = 7146; do { sum = sum + k % 10; k = k / 10; } while (k > 0); System.out.println (sum); What is the output. Select the answer that is closest A 5 B 10 C 15 D 20 E 25 Question 6 (2 marks) public class Q6 { public static void main (String[] args) { int i, j, k, sum; i=5; j=35; k=75; sum = j + 4 % i * k - 6; System.out.println ("result : " + sum.Valueof () ); } } What is the output? A 329 B 294 C 104 D 33 E Compile-time error Question 7 (2 marks) An instance variable is best defined as A a variable contained in each object of a class B a static variable C a variable local to a method D a constant variable E a parameter variable Question 8 (2 marks)
Which line of code checks to ensure that value of type int is strictly between zero and 100 and stores the answer in boolean b? A

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/12/2009 for the course CSC CSC 110 taught by Professor Anne during the Fall '04 term at University of Victoria.

### Page1 / 7

practicemult - Practice multiple choice exam questions....

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

View Full Document
Ask a homework question - tutors are online