Key_for_6EExam1_Ch1__2_

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

Info icon This 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
Image of page 1

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

View Full Document Right 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);
Image of page 2
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern