

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Unicode, Illegal Expression, Stored in Variable, Declare a Variable, Correct Expression, Statements Display, Method with Value
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


22C:21 Computer Science II: Data Structures Quiz 1B (15 Minutes) Some questions have more than one correct answers; please select all (Open book and notes; no computers) September 2, 2010
2 Which of the following are correct ways to declare variables?
A. int length; int width; B. int length, width; C. int length; width; D. int length, int width;
4 To declare a variable MAX_LENGTH inside a method with value 99.98, you write
A. int MAX_LENGTH = 99.98; B. float MAX_LENGTH = 99.98; C. double MAX_LENGTH = 99.98; D. long MAX_LENGTH = 99.98;
6 What is the result of 45 / 4?
A. 10 B. 11 C. 11. D. 12
8 25 % 1 is _____
A. 1 B. 2 C. 3 D. 4 E. 0
10 24 % 5 is _____
A. 1 B. 2 C. 3 D. 4 E. 0 12 To add a value 1 to variable x, you write A. 1 + x = x;
B. x += 1; C. x := 1; D. x = x + 1; E. x = 1 + x;
14 To add number to sum, you write
A. number += sum; B. number = sum + number; C. sum = Number + sum; D. sum += number; E. sum = sum + number;
16 Suppose x is 1. What is x after x -= 1?
A. 0 B. 1 C. 2 D. - E. -
18 What is x after the following statements?
int x = 1; x *= x + 1;
A. x is 1. B. x is 2. C. x is 3. D. x is 4. . 20 Are the following four statements equivalent? number += 1; number = number + 1; number++; ++number;
A. Yes B. No
22 What is the printout of the following code:
double x = 5.5; int y = (int)x; System.out.println("x is " + x + " and y is " + y);
A. x is 5 and y is 6 B. x is 6.0 and y is 6. C. x is 6 and y is 6 D. x is 5.5 and y is 5 E. x is 5.5 and y is 5.
24 What is the value of (double)5/2?
A. 2 B. 2. C. 3 D. 2. E. 3.
26 The expression (int)(76.0252175 * 100) / 100 evaluates to _________.
A. 76. B. 76 C. 76. D. 76.
28 Which of the following is the correct expression of character 4?
A. 4 B. "4" C. '\0004' D. '4'
30 Suppose x is a char variable with a value 'b'. What is the printout of the statement System.out.println(++x)?
A. a B. b C. c D. d
32 Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?
A. System.out.println(i); B. System.out.println((char)i); C. System.out.println((int)i); D. System.out.println(i + " ");
34 Will System.out.println((char)4) display 4?
A. Yes B. No
36 An int variable can hold __________.
A. 'x' B. 120 C. 120. D. "x" E. "120"
38 The expression "Java " + 1 + 2 + 3 evaluates to ________.
A. Java B. Java C. Java 123 D. java 123 E. Illegal expression
40 Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.
A. 66 B. B C. A D. Illegal expression