{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# HW4 - D always false 5 Can we always convert a for loop to...

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

COP 3502: HW 4 – CHAPTER 4 DUE DATE: FEB. 10 4:00 PM 1. What is the output of the following fragment? (3 points) int i = 1; int j = 1; while (i < 5) { i++; j = j * 2; } System.out.println(j); 2. Analyze the following code. What is the output? (4 points) int x = 1; while (0 < x) && (x < 100) System.out.println(x++); 3. What is the output of the following fragment? (3 points) for (int i = 0; i < 15; i++) { if (i % 4 == 1) System.out.print(i + " "); }

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

View Full Document
4. Suppose cond1 is a Boolean expression. When this while condition is true? (2 points) while (cond1) . .. A. always true B. in case cond1 is true C. in case cond1 is false
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: D. always false 5. Can we always convert a for loop to a while loop? How? (3 points) 6. Which of the loop statements always have their body executed at least once? (1 point) 7. Analyze the following code. (4 points) double sum = 0; for (double d = 0; d < 10; sum += sum + d) { d += 0.1; } A. The program has a syntax error because the adjustment statement is incorrect in the for loop. B. The program has a syntax error because the control variable in the for loop cannot be of the double type. C. The program compiles and runs fine. D. The program compiles but does not stop because d would always be less than 10....
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

HW4 - D always false 5 Can we always convert a for loop to...

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

View Full Document
Ask a homework question - tutors are online