Sp04midterm1 - Points off 1 2 3 4 Admin Total off Net Score...

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

View Full Document Right Arrow Icon
Points off 1 2 3 4 Admin Total off Net Score CS 307 – Midterm 1 – Spring 2004 Your Name____________________________________ Your UTEID __________________________________ Your USL's Name________________________________ Instructions: 1. There are 4 questions on this test. 2. You will have 2 hours to complete the test. 3. You may not use a calculator. 4. Please make your answers legible. 5. When code is required, write Java code. 6. The class style guide and coding standards are not in effect 7. You are not graded on the efficiency of your solutions 8. You may not use any classes' or methods from the Java Standard Library except as noted. You may use System.out.println, System.out.print, any classes' equals method, and native arrays. 1. (2 points each, 30 points total) Short answer questions. For code sample state the output. If the output would cause a syntax error answer "syntax error" and if it would cause a runtime error answer "runtime error". In the case of an error explain what caused the syntax error or runtime error. A. What is the output of the following code? int x = 4; int y = 7; int z = 3; int zz = x + y * z; System.out.println(zz); ____________________________________________ CS 307 – Midterm 1 – Spring 2004 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
B. What is the output of the following code? int x = 5; double a = 2.0; double b = x / a; System.out.println(b); _________________________________________________ C. What is the output of the following code? int[] list = {0, 1, 2, 3, 5, 7, 9, 11, 13}; System.out.println( list.length ); _________________________________________________ D. What is the output of the following code? int total = 0; for(int i = 0; i < 10; i++) for(int j = 1; j < 10; j = j * 2) total++; System.out.println( total ); _________________________________________________ CS 307 – Midterm 1 – Spring 2004 2
Background image of page 2
E. What is the output of the following code? From the String class. (character indices start at 0.) char charAt (int index) Returns the character at the specified index. String s = "duct tape"; String result = ""; for(int i = 2; i < s.length(); i = i + 3) result += s.charAt(i); System.out.println(result); _________________________________________________ F. What is the output of the following code when method guy is called? public void noir(int x, int y) { int z = x; x = y; y = z; } public void guy() { int a = 12; int b = 39; System.out.println( a + " " + b ); noir(a, b); System.out.println(a + " " + b ); } _________________________________________________ CS 307 – Midterm 1 – Spring 2004 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
For questions G through K consider the following class: public class Face { private String myEyeColor; private String myHairColor; public Face() { myEyeColor = "Brown"; myHairColor = "Brown"; } public void changeHair(String hair) { myHairColor = hair; } public void changeEyes(String eyes) { myEyeColor = eyes; } public String toString() { return myEyeColor + " " + myHairColor; } } G. What is the output of the following code when method lake is called? public void wobegone(Face f)
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.

This note was uploaded on 11/30/2010 for the course CS 307 taught by Professor Scott during the Spring '08 term at University of Texas.

Page1 / 16

Sp04midterm1 - Points off 1 2 3 4 Admin Total off Net Score...

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