15-100 Summer 2009
Quiz 0 (Practice)
20 Minutes
- Show your work!
- The purpose of this practice quiz is not to cover all the topics you
should know (see the class notes, hw's, and lectures for that!), but rather
to give you an idea of the kinds of questions you may be expected to answer.
Even then, there are many different kinds of questions, too many to present
here.
- In general, for "real" quizzes, you will not have access to
computers, notes, books, or any other materials. Just yourself and
your writing implement. This being practice, though, such rules do not
apply here, so you may collaborate on this practice quiz if you are so
inclined.
- If this were a "real" quiz, you would be allotted about 20 minutes to
finish it.
- Mystery Code / Arithmetic
Assuming that variables x, y, and z all hold non-negative integer values,
under what conditions in general will the following line of code crash?
int mystery = x / y / z - x /
(y / z);
- Binary Representations
- Name two advantages of 2's complement over sign-magnitude
- Convert decimal -11 into 5-digit two's complement
- What are the largest and smallest values, exactly, in 4-bit 2's
complement?
- Moore's Law
- Explain why some calculations involving Moore's Law involve the base-2
logarithm of a number.
- Moore's Law has been very accurate for decades now. Do you think
it could still apply in a hundred years? A billion years? Why
(or why not)?
- Reading (Chapter 1)
Note: every part of Chapter 1 is fair game, even if it is not
covered in lectures or on the hw's!
- In just a few words, distinguish a LAN from a WAN.
- How many bits are required to represent an IP address? Thus, how
many unique IP addresses are there?
- Name something that appears in the JDK but not in the JRE.
- True or False: The JRE contains class libraries and the JVM.
- Sum of Integers
Write a program that reads in a non-negative integer value, n, and prints
out the sum of the integers from 0 to n. For example, if n equals 3,
your code should print out 6 because 0 + 1 + 2 + 3 = 6. Note: To solve
this, you may not use loops (even if you know how) Instead, you should
use Gauss’s Formula:
0 + 1 + 2 + … + n = (1/2)n2 + (1/2)n
To verify, if n equals 3, Gauss’s Formula says:
0 + 1 + 2 + 3 = (1/2)32 + (1/2)3 = 9/2 + 3/2
= 12/2 = 6.
Yep. Hint: be sure to properly handle integer division and truncation, so
that your program produces the correct output for all legal inputs.
- The Algerian Flag
Be prepared to paint any of the flags we have covered, or any similar flags,
including centering objects in certain areas and rendering crescents, and
converting stars to their bounding circles. For example, try the
Algerian flag:

Actually, you are not responsible for the green portion inside the crescent
(why not?).