# fa06M1 - Points off 1 2 3 4 Total off Net Score CS 307...

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

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

View Full Document
C. What is the output of the following code? int[] data = {2, 1, 7, 3, 4, 2}; for(int i = 1; i < data.length; i++){ data[i] = data[i] + data[i-1]; } System.out.println( data[5] ); D. What is the output of the following code? int[][] mat = {{2, 3, 4}, {-1, 5, 10}, {4, 6, 7}}; for(int r = 0; r < mat.length; r++){ for(int c = 0; c < mat[0].length; c++){ if( r != c ){ mat[r][c] = mat[c][r]; } } } for(int i = 0; i < mat.length; i++) System.out.print( mat[i][2] + " "); E. What is the output of the following code when method kk9 is called? public void kk9(){ int total = 3; mm6( total, 2 ); System.out.print( total ); } public void mm6(int total, int n){ total = total * (n + 1); System.out.print(total + " " + n + " "); } F. Could a call to method rs41 ever result in a NullPointerException? Briefly explain why or why not. // pre: obj != null public void rs41(Object obj){ String s = obj.toString(); System.out.println( s ); } CS 307 – Midterm 1 – Fall 2006 2
For questions G – O consider the following classes and interfaces. public interface MinuteBasedPlan{ public int cost(int used); public int baseCost(); } // a calling plan with a base cost and a cost per minute public class CallingPlan implements MinuteBasedPlan{ private int incCost; private int basePlanCost; public CallingPlan(int cost, int base){ incCost = cost; basePlanCost = base; } public int cost(int used){ return (used * incCost) + basePlanCost; } public int baseCost(){ return basePlanCost; } public void priceIncrease(){ incCost++; } } public class CallingPlanWithBaseMin extends CallingPlan{ private int baseMin; public CallingPlanWithBaseMin(int cost, int base, int min){

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

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

### Page1 / 20

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