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

Info iconThis preview shows pages 1–4. 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 (Spring 2008) Section Professor's Name Student ID Your Name ※ Fill out the student information CORRECTLY or you w i l l get a demer it mark o f 1 point for every mistake you make. 1. Answer each question according to the instruction. 1-1. Choose an incorrect description in the following program. ( 4 ) (3 points) import java.util.*; public class Sample { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String value = keyboard.next(); System.out.println(value); } } The program doesn't have any programming errors. main() is a kind of method and has parameter. ' value ' stores a reference of an object of class String. The next() method is defined in Scanner class and returns an integer type value. System.in in line 4 is a parameter for the constructor of class Scanner . 1-2. What is the result of the following program? ( 2 ) (3 points) public class VariableTest { public static void main(String[] args) { final double PI = 3.14; int radius; double circum; radius = 3; System.out.println(radius); circum = 2 * PI * radius; System.out.println(circum); } } 0 0.0 3 18.84 3.0 18.0
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-3. What is the result of the following program? ( 4 ) (3 points) import java.util.*; public class ConsoleIO{ public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int n = 0; int a = keyboard.nextInt(); int b = keyboard.nextInt(); n = a / b; String c = keyboard.next(); System.out.println(n); System.out.println(c); } } 8 5 Hi, Hi! ? 1 Hi, Hi! 1.6 Hi, Hi! 1 Hi 1 Hi, 1.6 Hi, 1-4. What is the result of the following program? ( 4 ) (3 points) public class LoopStatements { public static void main(String[] args) { int i = 1; int number = 0; do { number += i; i++; } while(number < 10); System.out.println(i + ", " + number); } } 4, 10 4, 12 5, 15 5, 10 5, 11
Background image of page 2
- 3 - 1-5. What is the result of the following program? ( 5 ) (3 points) public class Point { private int x; private int y; public int getX() {return x;} public int getY() {return y;} public void setX(int newX) { x = newX; } public void setY(int newY) { y = newY; } public Point add(Point p) { x += p.getX(); y += p.getY(); return p; } public void print() { System.out.println("(" + x + ", " + y + ")"); } public static void main(String[] args) { Point p1 = new Point(); Point p2 = new Point(); p1.setX(3); p1.setY(2); p2.setX(4); p2.setY(3); p1.add(p2).add(p1); p1.print(); p2.print(); } } (11, 8) (4, 3) (3, 2) (4, 3) (7, 5) (7, 5) (7, 5) (8, 6) (7, 5) (11, 8) 1-6. Choose a correct statement. ( 3 ) (3 points) At least one constructor should be implemented in a class.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/09/2010 for the course CS CS101 taught by Professor Hwang during the Spring '10 term at 카이스트, 한국과학기술원.

Page1 / 14

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

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

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