Java_Midterm Exam_Summer 2009_Solution

Java_Midterm Exam_Summer 2009_Solution - Steve Houseman...

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

View Full Document Right Arrow Icon
Steve Houseman Page 1 10/5/2011 JAVA- Midterm Exam Time allowed 1 hour and 15 minutes Total = 15 points. Solution Instruction: Complete all 30 multiple choice questions (½ POINT EACH), by marking the correct answer on Scranton (Form No. 882-E). Use a Pencil. 1. A program written in the Java programming language can run on any platform because. .. A. Java Programming is derived from C++ B. The Java Virtual Machine (JVM) interprets the program for the native operating system C. The complier is identical to a C++ compiler D. Java is an Object Oriented Programming (OOP) language 2. What is the value of the variable c, after the execution of the following expressions? int a = 3; int b = 12; int c = 6; int d = 1; d = d * a; c = c + 2 * a; d = d - b / c; c = c * b % c; b = b / 2; A. 3 B. 6 C. 0 D. 2 3. Which of the following Java statements accesses the 7 th character in the String variable myString and place it in the char variable c . A. c = myString.charAt(7); B . myString = c.charAt(6); C. c = myString.charAt.(6); D. c = myString.charAt(6);
Background image of page 1

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

View Full DocumentRight Arrow Icon
Steve Houseman Page 2 10/5/2011 4. Consider the following code segment: int a = 32; int b = 10; double c = a/b; System.out.println(“The value of c is ” + c); The above code will produce the output: The value of c is 3.0 However, you expected the value of c to be 3.2. What should be done to get the desired result? A. we are performing integer division, then typecasting to a double. That is why the result is 3.0 and not 3.2. In order to obtain 3.2, change the third statement to double c = double a / b; B. we are performing integer division, then typecasting to a double. That is why the result is 3.0 and not 3.2. In order to obtain 3.2, change the third statement to double c = ( double ) a / b; C. cannot assign an int value to a double variable. D. Do nothing to change the third statement. Rerun the program. 5. What does the following code output? DecimalFormat percent = new DecimalFormat("0.00%"); System.out.println(percent.format(0.308)); A. 3.080% B. 30.80% C. .0308% D. 308.0% 6. The conversion from an object of a wrapper class to a value of its associated primitive type is called: A. Boxing B. Unboxing C. Converting D. Reinstantiating
Background image of page 2
Steve Houseman Page 3 10/5/2011 7. You coded the following program in the file Test.java: public class Test { public static void main(String[] args) { int a = 6; NumberFormat nf = NumberFormat.getCurrencyInstance(); } } When you compile, you get the following message: Test.java: Cannot find symbol Symbol: Class NumberFormat Location: Class Test NumberFormat nf = NumberFormat.getCurrencyInstance(); ^ Test.java: Cannot find symbol Symbol: variable NumberFormat Location: Class Test NumberFormat nf = NumberFormat.getCurrencyInstance(); ^ A. The getCurrencyInstance() method returns a formatting object that refelects the local currency. The $ sign is missing. B. The dot (.) operator can not be used in the format that is used here. Instead of
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.

Page1 / 11

Java_Midterm Exam_Summer 2009_Solution - Steve Houseman...

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