Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
127 views

Sample Test

This document is a sample midterm exam for CSE 114. It contains 7 questions worth a total of 100 points. The exam instructions specify that it is closed book and must be completed in 53 minutes. Answers should be written neatly in the spaces provided with no additional sheets.

Uploaded by

Nick As Tello
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Sample Test

This document is a sample midterm exam for CSE 114. It contains 7 questions worth a total of 100 points. The exam instructions specify that it is closed book and must be completed in 53 minutes. Answers should be written neatly in the spaces provided with no additional sheets.

Uploaded by

Nick As Tello
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CSE 114 Sample Midterm Exam 1 Version 1

Name:

First

Last

Student ID # _________________________________

Question #

Points
Available

1
2
3
4
5
6
7
Total:

10
10
10
10
20
10
30
100

Points
Earned

Directions: You have 53 minutes to complete this exam. Write all answers neatly in
the space provided. Please do not separate exam sheets. No additional exam sheets are
provided. Scrap paper is provided per request.
You must write with a pen.
Closed book exam: you are not allowed to use the textbook, lecture notes, cheat sheets
or anything else beside your brain during the exam.
Use well-named variables and include any documentation where you feel it is necessary
to understand your algorithms.

CSE 114 Sample Midterm Exam 1 Version 1

Question 1
a. (1 point) If you attempt to add an int, a byte, a long, and a double, the result will be a
__________ value.
A. double
B. byte
C. long
D. int

b. (1 point) 25 % 1 is _____
A. 3
B. 1
C. 2
D. 0
E. 4

c. (5 points) Multiple answers: To add number to sum, you write (Note: Java is case-sensitive)
A. number += sum;
B. number = sum + number;
C. sum = sum + number;
D. sum += number;
E. sum = Number + sum;

d. (1 point) Note that the Unicode for character 'A' is 65. The expression 'A' + 1 in the statement
System.out.print('A' + 1); evaluates to ________.
A. 66
B. "A1"
C. Illegal expression
D. 'B'

e. (1 point) The "less than or equal to" comparison operator in Java is __________.
A. <<
B. =<
C. <=
D. !=
E. <

f. (1 point) In Java, the word true is ________.


A. a Boolean literal
B. same as value 0
C. a Java keyword
D. same as value 1

CSE 114 Sample Midterm Exam 1 Version 1

Question 2
a (5 points) Which of the Boolean expressions below are incorrect?
A. (true) && (3 => 4)
B. (x != 0) || (x = 0)
C. !(x > 0) && (x > 0)
D. (x > 0) || (x < 0)
E. (-10 < x < 0)

b. (5 point) What is the printout of the following switch statement?


char ch = 'a';
switch (Character.toUpperCase(ch)) {
case 'A':
System.out.print(ch); break;
case 'B':
System.out.print(ch); break;
case 'C':
System.out.print(ch); break;
case 'D':
System.out.print(ch); break;
default:
S.o.p(ch);
}
A. aa
B. ab
C. a
D. abcd
E. abc

CSE 114 Sample Midterm Exam 1 Version 1

Question 3
a. (4 point) Analyze the following code:
Code 1:
int number = 45;
boolean even;
if (number % 2 == 0)
even = true;
else
even = false;
Code 2:
int number = 45;
boolean even = (number % 2 == 0);
A. Code 2 has compile errors.
B. Code 1 has compile errors.
C. Both Code 1 and Code 2 have compile errors.
D. Both Code 1 and Code 2 are correct.

b. (2 point) Analyze the following code:


if (x < 100) & (x > 10)
System.out.println("x is between 10 and 100");
A. The statement has compile errors because (x<100) & (x > 10) must be enclosed inside
parentheses.
B. The statement has compile errors because (x<100) & (x > 10) must be enclosed inside
parentheses and the println(?) statement must be put inside a block.
C. The statement compiles fine, but has a runtime error.
D. The statement compiles fine.

c. (4 point) What is the printout of the following switch statement?


char ch = 'b';
switch (ch) {
case 'a':
System.out.print(ch);
case 'b':
System.out.print(ch);
case 'c':
System.out.print(ch);
case 'd':
System.out.print(ch);
}
A. b
B. bcd
C. bbb
D. abcd
E. bb

CSE 114 Sample Midterm Exam 1 Version 1

Question 4
a. (5 points) What is the output of the following code?
boolean even = false;
System.out.println((even ? "true" : "false"));
A. false
B. nothing
C. true
D. true false

b. (5 points) What is the value in count after the following loop is executed?
int count = 0;
do {
System.out.println("Welcome to Java");
} while (count++ < 9);
System.out.println(count);
A. 9
B. 8
C. 11
D. 10
E. 0

Question 5 (20 points)


Write a method to compute the following series:

1 2
i
m(i ) ...
3 5
2i 1

CSE 114 Sample Midterm Exam 1 Version 1

Question 6 (10 Points)


Write a method that will display numbers from 1 to n, 7 numbers per line. The numbers are
separated by one space.

CSE 114 Sample Midterm Exam 1 Version 1

Question 7 (30 Points):


Write a loop that displays the following pattern.
12345678987654321
234567898765432
3456789876543
45678987654
567898765
6789876
78987
898
9

CSE 114 Sample Midterm Exam 1 Version 1

You might also like