fa07M1 - 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
CS 307 – Midterm 1 – Fall 2007 1 Points off 1 2 3 4 Total off Net Score CS 307 – Midterm 1 – Fall 2007 Your Name____________________________________ Your UTEID __________________________________ Circle yours TA’s name: David Joseph Ola 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 = 3; int y = 2; x *= x + y * 2; System.out.println( x ); B. What is the output of the following code? int a = 13; int b = 20; System.out.println( a % b );
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 307 – Midterm 1 – Fall 2007 2 C. What is the output of the following code? int value = 80; int inc = 5; while( value > 0){ value -= inc; inc *= 2; } System.out.println( inc ); D. What is the output of the following code? int[] data = {4, 2, 5, -1, 3}; for(int i = 1; i < data.length; i++){ data[i] += data[i-1]; } for(int i = 0; i < data.length; i++){ System.out.print( data[i] + " "); } E. What is output when method one is called? public static int two(int x, int y){ x = x / 2; y++; return x + y; } public static void one(){ int a = 5; int b = 3; System.out.print( two(a, b) + " "); System.out.print( a + " " + b ); }
Background image of page 2
3 F. What is the output when method three is called? public static int four(int[] list){ list[0]++; list[1]++; return list[0] * list[1]; } public static void three(){ int[] data = {2, 3}; System.out.print( four(data) + " "); System.out.print( data[0] ); } G. What is the output when method five is called? public static String six(String s){ s = "abc"; return "" + s.charAt(0) + s.charAt(2); } public static void five(){ String s1 = "xyz"; System.out.print( six(s1) ); System.out.print( s1 ); } H. Can method firstCharIsLetter generate an exception? Explain why or why not. // pre: s != null
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 / 18

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