Lecture 18 PowerPoint

advertisement

“The Last Lecture” Lecture

14

Apple[0] Apple[1] Apple[2] Apple[3] Apple[4]

Lecture 14 Announcements

Assignment 4 due Wednesday, August 24th by midnight!

Monday, August 24th: Final Exam

Monday, August 24 th : Extra Credit 01 due by midnight

Today’s Topics

• Course/Instructor Evaluation (CIE)

• Passing and Returning Arrays (Review)

• String Class

• Final Exam ( Wednesday, August 24 )

• Assignment 4 ( Wednesday, August 24 )

• Extra Credit 01 ( Wednesday, August 24 )

Course/Instructor Evaluations http://www.cascadia.edu

BIT115

But First ...

The Last Quiz

Passing and Returning Arrays

Passing Arrays as Arguments

 Arrays are objects.

 Their references can be passed to methods like any other object reference variable.

showArray(numbers);

5 10 15 20 25 30 35 40

Address public static void showArray( int[] array)

{ for ( int i = 0; i < array.length; i++)

System.out.print(array[i] + " " );

}

Example: PassArray.java

Passing and Returning Arrays

In Last Wednesday’s Class we learned how you could pass an array into a method.

Today we’re going to take this to the next step to learn how you can return an array from a method.

A method can return a reference to an array. To do so, the return type of the method must be declared properly. For example, look at the following method definition:

double is the return type

 public static double[] getArray() // <-- No parameters called

{ double[] array = {1.2, 2.3, 4.5, 6.7, 8.9} return array;

}

return sends back a double

The getArray method is a public static method that returns an array of doubles.

See Example: ReturnArray.java

LECTURE 14:

ICE : Array Returns

But, first, a look at the String class and the Extra Credit

Download