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

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 2005 Your Name____________________________________ Your UTEID __________________________________ Your TAs name ________________________________ (Peter or David) 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 unless stated. 8. When writing code for questions 2 and 3 assume the preconditions of the method are met. 9. 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) Place your answers on the attached sheet . Short answer questions. For code sample state the output. If the code would cause a syntax error answer "syntax error" and if it would cause a runtime error answer "runtime error". A. What is the output of the following code? int x = 4; int y = 3; int z = 2; x = x + z * y; System.out.println( x ); CS 307 – Midterm 1 – Spring 2005 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. Show the contents of list after this code segment completes. int[] list = {2, 6, 3, 7, 5, 9, 9}; int temp1; int temp2; for(int i = 0; i < list.length; i++) { temp1 = (i * i) % list.length; temp2 = list[i]; list[i] = list[temp1]; list[temp1] = temp2; } C. What is the output of the following code? int[][] mat = new int[2][3]; for(int c = 0; c < mat[0].length; c++) { for(int r = 0; r < mat.length; r++) { mat[r][c] = r – c; } } for(int r = 0; r < mat.length; r++) { for(int c = 0; c < mat[0].length; c++) { System.out.print( mat[r][c] + " " ); } } CS 307 – Midterm 1 – Spring 2005 2
Background image of page 2
D. Consider the following methods which are all in the same class. public void comm() { System.out.print("A"); } public void graph(int x) { System.out.print("B"); for(int i = 0; i < x; i++) { comm(); } System.out.print("B"); } public void plan(int x) { comm(); graph(2); for(int i = 0; i < x; i++) { System.out.print("C"); } graph(1); } What is output by the following method call? plan(3); E. What is the output of the following code? public void art(int p, int q) { System.out.print(p + " " + q); p++; q--; System.out.print(" " + p + " " + q); } int p = 3; int q = 4; art(p, q); System.out.print(" " + p + " " + q); CS 307 – Midterm 1 – Spring 2005 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 F through L consider the following two classes. public class Superhero
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 / 15

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

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