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

This preview shows pages 1–5. Sign up to view the full content.

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

View Full Document
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
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

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

View Full Document
For questions F through L consider the following two classes. public class Superhero
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online