G the output above indicates that elements in

This preview shows page 3 - 5 out of 5 pages.

otherwise (e.g., the output above indicates that elements in position 3, 5, 6, 7, 16 and 19 are all false). private void printXs(boolean[] hasDone) { System.out.println("01234567890123456789"); } 18 012345678901234567890 XXX X XXXXXXXX XX X
Image of page 3

Subscribe to view the full document.

CompSci 101 Lecture 13 4 Ex04 Complete the getLargest() method which returns the largest value in the parameter array. private int getLargest(int[] numbers) { int largest = return largest; } 19 { 3, 8, 4, 9, 5, 5, 23, 14 } Largest 23 { 33, 23, 41, 9, 17, 51, 23, 45 } Largest 51 Making copies of arrays 1 What is the difference (if any) between the following sections of code (A, B, C)? 20 int[] balances1 = new int[79]; // B int[] balances2 = new int[79]; int[] balances1 = new int[79]; // A int[] balances2 = balances1; int[] balances1 = new int[79]; // C int[] balances2 = new int[balances1.length]; Making copies of arrays 2 What is the output? 21 int[] balances1 = new int[79]; int[] balances2 = balances1; balances1 c c c balances2 balances1[0] = 345; balances2[0] = 21; System.out.println(balances1[0]); System.out.println(balances2[0]); Making copies of arrays 3 What is the output? 22 balances1 d c c balances2 balances1[0] = 345; balances2[0] = 21; System.out.println(balances1[0]); System.out.println(balances2[0]); int[] balances1 = new int[79]; int[] balances2 = new int[balances1.length]; d Making copies of arrays 4 What is the difference (if any) between the following sections of code (A, B)? int[] balances1 = new int[79]; // B int[] balances2 = new int[balances1.length]; for (int i=0; i<balances1.length; i++) { balances2[i] = balances1[i]; } int[] balances1 = new int[79]; // A int[] balances2 = balances1; for (int i=0; i<balances1.length; i++) { balances2[i] = balances1[i]; } 23 Ex05 Complete the getSumArray() method which returns a new array which is the sum of the two parameter arrays. Assume that the arrays have the same length. private int[] getSumArray(int[] a1, int[] a2) { int[] sumArray; return sumArray; } 24 { 3, 8, 4, 9, 5, 5, 23, 14 } { 33, 23, 41, 9, 17, 51, 23, 45 } { 36, 31, 45, 18, 22, 56, 46, 59 }
Image of page 4
CompSci 101 Lecture 13 5 25 What you need to know Declaring an array. Creating the array space. Assigning to individual elements of an array. Processing the elements of the array. Copying arrays.
Image of page 5
You've reached the end of this preview.

{[ 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