SP06M1_1 - Points off 1 2 3 4 Total off Net Score CS 307...

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

View Full Document Right Arrow Icon
Points off 1 2 3 4 Total off Net Score CS 307 – Midterm 1 – Spring 2006 Your Name____________________________________ Your UTEID __________________________________ TA’s Name ___________________________________ (Vinod or Chendi) Instructions: 1. Please turn off your cell phones 2. There are 4 questions on this test. 3. You will 2 hours to complete the test. 4. You may not use a calculator. 5. Please make your answers legible. 6. When code is required, write Java code. 7. When completing a method, assume the preconditions of the method are met. 8. When you complete the test show the proctor your UTID and give them the test and any scratch paper. Please leave the room quietly. 1. (2 points each, 30 points total) Short answer questions. Place your answers on the attached answer sheet. For code sample state the output. If the code would cause a syntax error answer "syntax error". If it would cause an exception error answer "exception". If it would result in an infinite loop answer "infinite loop". Place you answers on the attached answer sheet. A. What is the output of the following code? int x = 3; int y = x – 3 * 3 + x; x++; System.out.println( x + “ “ + y); B. What is the output of the following code? int x = 2; int y = x; for(int i = 0; i < 3; i++) y = y * 2; System.out.println( x + “ “ + y ); CS 307 – Midterm 1 – Spring 2006 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
C. What is the output of the following code? int x = 2; for(int i = 0; i < x; i++) x = x * 3; System.out.println( x ); D. What is the output of the following code? int[] list = {5, 2, 1, 4, 3, 7, 12, 5}; for(int i = list[1]; i < list.length; i = i + 2) list[i] = list[i] + 3; System.out.println( list[1] + “ “ + list[2] + “ “ + list[6] ); E. What is the output of the following code? int[] list = new int[5]; for(int i = list.length – 1; i >= 0; i--) list[i] = -i + 2; System.out.println( list[0] + “ “ + list[3] ); F. What is the output of the following code? String[] sList = new String[10]; System.out.println( sList[4].length() ); G. What is the output of the following code when method led is called? public int who(int x) { return x + 2; } public int airplane(int x) { return (x * 2) + who(x); } public void led() { int y = 4; y = who(y) + airplane(2); System.out.println( y ); } CS 307 – Midterm 1 – Spring 2006 2
Background image of page 2
What is the output of the following code when method stone is called? public void pink(int x, int y) { x = x * 2; y = y + 2; System.out.print( x + “ “ + y ); } public void stone() { int x = 3; int y = 2; pink(x, y); System.out.print( x + “ “ + y ); } For questions I – R consider the following class: public class Size { private int weight; private int height; public Size() { this(7, 20); } public Size(int w, int h){ weight = w; height = h; } public void grow(){ weight += 2; height++; } public void diet() { weight--; } public void toString() { return weight + “ “ + height; } } I. What is the output of the following code? // in a class other than Size
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 / 20

SP06M1_1 - Points off 1 2 3 4 Total off Net Score CS 307...

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