{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# l2 - a compile-time or a run-time error in the C/R column...

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

CS121 Autumn 2009 Lecture #2 exercises Reading: Sedgewick&Wayne 1.1 and 1.2 The purpose of these exercises is to allow you to test your understanding of the material covered in today’s lecture. You are welcome to turn in your answers at the next lecture to get feedback from us, but you are not required to do so. These exercises are intended to take less than an hour, assuming you have done the reading. If you cannot figure out the answer for a question (or part Questions 1&2) in five or ten minutes, please ask for help. Problem 1: Copy the directory /home/amr/cs121/L2 to your cs121 directory. In it, you will find a series of programs named A.java , B.java , etc. These programs are intended to perform the same task. A.java compiles and runs correctly. Some of the remaining programs do not compile, the others compile, but generate an error at runtime. Fill in the following table. For each program, record whether the error has

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.

Unformatted text preview: a compile-time or a run-time error in the C/R column and give the source of the error in the explanation column. This exercise is tedious, but the time you spend learning about how to identify syntax errors, will save you frustration later. Program C/R Explanation B C D E F Problem 2 : For each part, state the value of a (and b ) after evaluating the code fragment. (a) int a = 10/3; (b) boolean a = true; a = !a; a = !a; a = !a; (c) double a; double b = 1.0; double c = 2.0; double d = 3.0; a = 4.0 * b * c/d * d; b = 4.0 * b * c/(d * d); Problem 3: Assuming x and y are declared to be double s. Write an expression to compute x/y 3 . Problem 4: Assume a and b are int s. Write an expression computing whether a is equal to b without using the == or != operators....
View Full Document

{[ snackBarMessage ]}