{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# HW3 - 7 Analyze the following code and check one of the...

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

COP 3502: HW 3 CHAPTER 3 DUE DATE: FEB 3 4:00 PM Please turn in the homework in in-line Sakai format (Copy and paste from your .doc or .docx document). 1. Suppose cond1 and cond2 are two Boolean expressions. When the condition (cond1 && cond2) will be true? What about condition (cond1 || cond2)? (4 points) 2. Explain what are the short- circuit operators. Is “!” a short circuit operator? (4 points) 3. __________ are the boolean operators. (More than 1 choice possible) (2 points) A. > B. ! C. && D. ^ 4. What is y after the following switch statement? (2 points) int x = 0; int y = 0; switch (x + 1) { case 0: y = 0; case 1: y = 1; default: y = -1 }

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

View Full Document
5. In a switch statement, the default case must appear last among all cases. Otherwise, it would result in a compilation error. (1 point) 6. What is 1.0 + 1.0 + 1.0 == 3.0? (3 points)
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 7. Analyze the following code and check one of the answers: (3 points) // Enter an integer String numString = JOptionPane.showInputDialog(null, "Enter a number:", "Exam Input", JOptionPane.QUESTION_MESSAGE); int number = Integer.parseInt(numString); if (number <= 0) System.out.println(number); A. System.out.println(number); must be placed inside braces; B. number entered from the input cannot be negative. C. The if statement is wrong, because it does not have the else clause; D. If number is zero, number is displayed; E. If number is positive, number is displayed. 8. Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? (2 points) A. (1 > x > 100) || (x < 0) B. ((x < 100) && (x > 1)) || (x < 0) C. 1 < x < 100 && x < 0 D. ((x < 100) && (x > 1)) && (x < 0)...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

HW3 - 7 Analyze the following code and check one of the...

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

View Full Document
Ask a homework question - tutors are online