{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

public class Quiz2Answers { //********************************************************************************* ******* // Variations on the first question. //********************************************************************************* ******* // first question for Thurs 8:00AM, Fri 11:00AM, CS1111 public static int[] twoSmallest (int[] A){ int ret [] = {Integer.MAX_VALUE, Integer.MAX_VALUE}; for(int i = 0; i < A.length; i++){ if(A[i] < ret[0]){ ret[1] = ret[0]; ret[0] = A[i]; } else if(A[i] < ret[1]){ ret[1] = A[i]; } } return ret; } // first question for Thurs 9:30AM, Thurs 8:00PM public static int[] makeRange (int A, int B){ int ret [] = new int[B-A+1]; for(int i = 0; i < ret.length; i++){ ret[i] = A + i; } return ret; } // first question for Thurs 11:00AM, Thurs 6:30PM public static int[][] rowSubtract (int [][] A, int [] V){ int ret [][] = new int [A.length] [A[0].length]; for(int i = 0; i < A.length; i++) for(int j = 0; j < A[0].length; j++) ret [i][j] = A[i][j] - V[j]; return ret; } // first question for Thurs 12:30PM, Thurs 5PM, Fri 12:30PM public static double[] rowSums (double [][] A){ double ret[] = new double [A.length]; for(int i = 0; i < A.length; i++) for(int j = 0; j < A[0].length; j++) ret [i] += A[i][j]; return ret; } // first question for Thurs 2:00PM, Thurs 3:30PM public static double[] diagonal (double [][] A){ double ret[] = new double [A.length]; for(int i = 0; i < A.length; i++) ret [i] = A[i][i]; return ret; }

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

View Full Document
//********************************************************************************* ******* // Variations on the second (recursion) question.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern