Quiz2 - EE 322C Data Structures Fall 2008 Date: 09/18/2008...

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

View Full Document Right Arrow Icon
EE 322C Data Structures Fall 2008 Date : 09/18/2008 Instructor: Dr. Ramesh Yerraballi Grader: Senthil K Chellappan (senthil@mail.utexas.edu) Quiz 2 Due date : 9/24 11:55 pm Points available : 60 points NAME (First, Middle, Last) Zachary Paul Anderson Instructions: Attempt the questions by yourself first. Reading the material should help you with this. Don’t rely on the computer to find your answer. Use it to improve and verify your understanding. Please type up your final answers in this word document with prefix “Answer:” after each question. Indicate your name above. 1. What is wrong with the following code (trying to resize an array)? (5 points) public static void resize(int [] arr) { int [] old = arr; arr = new int[old.length * 2 + 1]; for (int i = 0; i < old.length; i++) arr[i] = old[i]; } Answer: Once an array is instantiated, the contents can be manipulated but the size cannot. 2. What is the output and why? (3 points) public static void SpaceChar() { System.out.println(1 + ' ' + 2 + " " + 3); } Answer: 35 3
Background image of page 1

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

View Full DocumentRight Arrow Icon
The space ‘ ‘ is taken as a char literal, so in this context you add the integer value 32 + 1 + 2 which gives you the 35. The string “ “ cannot be added to this so it is appended as is the 3. 3. What is the following code snippet doing and why? Assume that Complex is a class that is defined with a constructor taking two int arguments. Complex represents complex numbers of the form x+iy. (5 points) public static void main(String [] args) { Complex c1 = new Complex(0, 2); Complex c2 = new Complex(0, 4); swap(c2, c1); } public static void swap(Complex c1, Complex c2) {
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Quiz2 - EE 322C Data Structures Fall 2008 Date: 09/18/2008...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online