6ESampleExam2_Ch3__4_

6ESampleExam2_Ch3__4_ - Name:_ Covers Chapters 3 and 4...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Name:_______________________ Covers Chapters 3 and 4 GCIS501 Advanced Programming Gannon University Instructor: YK Liu Part I: Multiple Choice Questions. 1. Analyze the following code: // 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. The if statement is wrong, because it does not have the else clause; b. System.out.println(number); must be placed inside braces; c. If number is zero, number is displayed; d. If number is positive, number is displayed. e. number entered from the input cannot be negative. 2. What is the output of the following code: (Please indent the statement correctly first. This will help you read the program.) int x = 9; int y = 8; int z = 7; if (x > 9) if (y > 8) System.out.println("x > 9 and y > 8"); else if (z >= 7) System.out.println("x <= 9 and z >= 7"); else System.out.println("x <= 9 and z < 7"); a. x > 9 and y > 8; b. x <= 9 and z >= 7; c. x <= 9 and z < 7; d. None of the above. 3. Analyze the following code: String numString = JOptionPane.showInputDialog(null, "Enter a number:", "Exam Input", JOptionPane.QUESTION_MESSAGE); 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
int number = Integer.parseInt(numString); if (number <= 0) System.out.println(number); System.out.println(number); a. number is always printed out at least once; b. number is printed out twice if number is zero; c. number is printed out twice if number is negative; d. number is printed out once if number is positive. e.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

6ESampleExam2_Ch3__4_ - Name:_ Covers Chapters 3 and 4...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online