2008fall_mid - 1 (30) 2 (20) 3 (20) 4 (30) Total (100)...

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

View Full Document Right Arrow Icon
- 1 - 1 (30) 2 (20) 3 (20) 4 (30) Total (100) CS101 Introduction to Programming Midterm Exam (Fall 2008) Section Professor's Name Student ID Your Name ※ Fill out the student information CORRECTLY or you w i l l get 1 po int o f f for each mistake you make. 1. Answer each question according to the instruction. 1-1. What is the result of the following program? ( 4 ) (3 points) public class switchTest { public static void main(String[] args) { int test = 3; switch(test) { case 1 : System.out.print("One"); break; case 2 : System.out.print("Two"); break; case 3 : System.out.print("Three"); case 4 : System.out.print("Four“); break; default : System.out.print("End"); break; } } } OneTwoThree ThreeEnd
Background image of page 1

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

View Full DocumentRight Arrow Icon
- 2 - 1-2. Which of the following may be used as variable names in Java? ( 3 ) (3 points) 1stPlayer long TimeLimit static myprogram.java 1-3. Which variable assignments make the condition in the if statement false . ( 5 ) (3 points) boolean a = true, b = false; if (a || b) int a = 4; double b = 4.0; if (a == b) int a = 10, b = 5; if (a == b*2) int a = 8, b = 8; if (a == b--) int a = 100; boolean b = true; 1-4. What is the result of the following program? ( 1 ) (3 points) public class drawTriangle { public static void main(String[] args) { int height = 4; for(int i = 1; i <= height; i++) { for(int j = 1; j <= height - i; j++) { System.out.print("+"); } for(int k = 1; k <= i; k++) { System.out.print(" "); } System.out.println(); } } } +++ ++ + + ++ +++ ++++ + ++ +++ ++++ ++++ +++ ++ + ++++ +++ ++
Background image of page 2
- 3 - 1-5. Choose a correct keyword for each blank ( ) (3 points) (a) java.util.*; public class inputTest { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int n = keyboard.nextInt(); (b) d = keyboard.nextDouble(); (c) s = keyboard.next(); } } int float double char String import (a) 6 (b) 3 (c) 5 1-6. What is the result of the following program? ( 4 ) (3 points) public class Test6 { public static void main(String[] args){ int a = 2, b = 3; double c = 0; System.out.println("a = " + (a++)); System.out.println("b = " + (++b)); System.out.println("c = " + c); c = a / b; System.out.println("a = " + (a++)); System.out.println("b = " + (++b)); System.out.println("c = " + c); } } ①a = 3 b = 4 c = 0.0 a = 4 b = 5 c = 0.75 ② a = 3 b = 4 c = 0.0 a = 4 b = 5 c = 0.0 ③ a = 2 b = 4 c = 0.0 a = 3 b = 5 c = 0.75 ④ a = 2 b = 4 c = 0.0 a = 3 b = 5 c = 0.0 ⑤ a = 3 b = 3 c = 0.0 a = 4
Background image of page 3

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

View Full DocumentRight Arrow Icon
- 4 - 1-7. Fill out the blanks in the main method so that the following results can produced. (6 points)
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

2008fall_mid - 1 (30) 2 (20) 3 (20) 4 (30) Total (100)...

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

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