Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367.

Similar presentations


Presentation on theme: "1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367."— Presentation transcript:

1 1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367

2 2 Announcements Program 4 –Due April 23 (that’s 3 weeks!) –This is a HARD program –Start early

3 3 Program 4 Demo

4 4 Questions?

5 5 Today in COMP 110 More about arrays Info for program 4

6 6 You have Seen Arrays Before import java.util.*; public class Arguments { public static void main(String[] args) { for(int i = 0; i < args.length; i++) { System.out.println(args[i]); } } } Build  Run Arguments

7 7 Arrays in Classes Instance Variable private int[] intArray; public static void setLength(int len) { intArray = new int[len]; }

8 8 Array of Classes Smiley[] smile = new Smiley[3]; 104525842836 True GREEN 3 False BLUE 1 False CYAN 4

9 9 Arrays as Arguments public void changeArray(int[] a) { int len = a.length; a[len] = 25; } 234752147 25

10 10 Arrays as Return Types public float[] buildArray(int len) { float[] ret = new float[len]; for(int i = 0; i < len; i++) { ret[i] = i*1.5; } return ret; }

11 11 Types int[] array = new int[3]; array[0] = 5; array[1] = 6; array[2] = 8; What is the type of array? What is the type of array[2]?

12 12 Indexed variables as arguments public void myMethod(int, Smiley) this.myMethod(intArray[2], sArray[0]); Read FAQ on p. 440 Cannot change value Can change smiley

13 13 Swap 12345

14 14 2D Arrays Int[][] twoD = new int[3][4] 0123 01352 17397 28545 row column

15 15 Selection Sort For (index = 0; index < length; index++) Find index of smallest value of array from index to length Swap values of current index and the index with the smallest value

16 16 Selection Sort 04739628 12739648 22379648

17 17 Bubble Sort 4759238 4579238 4572938 4572398 4572389

18 18 Friday Lab 7 Sorting Algorithms


Download ppt "1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367."

Similar presentations


Ads by Google