{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Quiz2Answers

Quiz2Answers - public class Quiz2Answers cfw Variations on...

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

View Full Document Right Arrow Icon
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; }
Image of page 1

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

View Full Document Right Arrow Icon
//********************************************************************************* ******* // Variations on the second (recursion) question.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern