sp07M1 - 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 2007 Your Name____________________________________ Your UTEID __________________________________ Circle yours TA’s name: Alison Aparajit Vineet 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 or any other electronic devices while taking this test. 5. Please make your answers legible. 6. When code is required, write Java code. 7. When writing a method, assume the preconditions of the method are met. 8. When writing a method you may add helper methods if you wish. 9. 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". A. What is the output of the following code? int x = 5; int y = 3; int z = x / y + x * y; System.out.println( z ); B. What is the output of the following code? int x = 128; int y = 0; while( x > 3 ){ x /= 2; y++; } System.out.println( y + "_" + x ); CS 307 – Midterm 1 – Spring 2007 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[] data = {5, 2, 0, 4, 3, 1}; int tgt = 0; for(int i = 0; i < 4; i++) tgt = data[tgt]; System.out.println(tgt); D. What is the output of the following code? final int SIZE = 4; char[][] letters = new char[SIZE][SIZE]; String alpha = "abcdefghijklmnopqrstuvwxyz"; int in = alpha.length() - 1; for(int c = SIZE - 1; c >= 0; c--){ for(int r = SIZE - 1; r >= 0; r--){ letters[r][c] = alpha.charAt(in); in--; } } for(int i = 0; i < SIZE; i++) System.out.print( letters[i][i] ); E. When method thorndale is called the output is 2323 . Briefly explain why. public void roundTop(int x, int y){ x = x * 2; y = y + 2; } public void thorndale(){ int x = 2; int y = 3; System.out.print( "" + x + y ); roundTop(x, y); System.out.print( "" + x + y ); } CS 307 – Midterm 1 – Spring 2007 2
Background image of page 2
What is the output when method industry is called? public int carmine(int[] list){ int total = 0; try{ for(int i = 0; i < 10; i++) total = list[i]; } catch(NullPointerException e){ total = -1; } catch(ArrayIndexOutOfBoundsException e){ total = -2; } return total; } public void industry(){ int[] data = {2, -3, 4, -5, 6, -5}; System.out.println( carmine(data) ); } G. Is the code in method carmine in question F a proper use of a try - catch block? Briefly explain why or why not.
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 11/30/2010 for the course CS 307 taught by Professor Scott during the Spring '08 term at University of Texas at Austin.

Page1 / 21

sp07M1 - 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