Key_for_6EExam1_Ch1__2_

Key_for_6EExam1_Ch1__2_ - System.out.println"k is"...

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

View Full Document Right Arrow Icon
Key for Exam 1 Part I: Multiple Choice Questions: (1 pt each) 1. a 2. d 3. c 4. b b (6) 5. b (0) 6. c (2) 7. b (2) 8. c (5) 9. d (12) 10. d (0) 11. d 12. b 13. a 14. a 15. d 16. b 17. b 18. d 19. a 20. e 21. a Which of the following assignment statements is correct to assign character 5 to c? 22. b 23. d 24. b 25. c 26. a 27. d 28. a c 29. a 30. b 31. c 32. d 33. c 34. e 35. b Part II: Find all syntax errors in the following code: (Please turn Word Reviewing to (5 pts) public class Test { public void main(String[] args) { int i = 0; int j = i + 1; int k = (int)5.5; System.out.println("j is " + j + "and k is " + k); } 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
} Part III: Show the output of the following code: (5 pts) public class Test { public static void main(String[] args) { int x1, x2, i, j, k, y, z; float f; x1 = 1; x2 = 1; y = 5 + x1--; z = 5 + ++x2; i = 6 % 4; j = 1; j += j + 3; k = 25 / 2; f = (float)((2 / 5) * k); System.out.println("x1 is " + x1); System.out.println("x2 is " + x2); System.out.println("i is " + i); System.out.println("j is " + j);
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println("k is " + k); System.out.println("y is " + y); System.out.println("z is " + z); System.out.println("f is " + f); } } x1 is 0 x2 is 2 i is 2 j is 5 k is 12 y is 6 z is 7 f is 0.0 Part III IV : Write a complete program named Exam1.java. The program reads three double numbers from the keyboard and displays the average of these three numbers. (5 pts) import javax.swing.JOptionPane; public class Test { /**Main method*/ public static void main(String args) { // Prompt the user to enter an integer String intString = JOptionPane.showInputDialog( "Enter an integer:"); // Convert string to int int number = Integer.parseInt(intString); 2 // Display results System.out.println("Is the number " + number + " between 1 and 1000 " + (number >= 1 && number <= 2000)); } } 3...
View Full Document

This note was uploaded on 01/17/2012 for the course GCIS 501 taught by Professor Liu during the Fall '09 term at Gannon.

Page1 / 3

Key_for_6EExam1_Ch1__2_ - System.out.println"k is"...

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