{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

17-apr02 - • array[0 = 5 • array[1 = 6 • array[2 = 8...

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

View Full Document Right Arrow Icon
1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367
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
2 Announcements Program 4 Due April 23 (that’s 3 weeks!) This is a HARD program Start early Start early Start early
Image of page 2
3 Program 4 Demo
Image of page 3

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

View Full Document Right Arrow Icon
4 Questions?
Image of page 4
5 Today in COMP 110 More about arrays Info for program 4
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 6
7 Arrays in Classes Instance Variable private int[] intArray; public static void setLength(int len) { intArray = new int[len]; }
Image of page 7

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

View Full Document Right Arrow Icon
8 Array of Classes Smiley[] smile = new Smiley[3]; 1045 2584 2836 True GREEN 3 False BLUE 1 False CYAN 4
Image of page 8
9 Arrays as Arguments public void changeArray(int[] a) { int len = a.length; a[len] = 25; } 23 47 52 14 7 25
Image of page 9

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

View Full Document Right Arrow Icon
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; }
Image of page 10
11 Types int[] array = new int[3];
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
Image of page 13

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

View Full Document Right Arrow Icon
Image of page 14
Image of page 15

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

View Full Document Right Arrow Icon
Image of page 16
Image of page 17

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

View Full Document Right Arrow Icon
Image of page 18
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • array[0] = 5; • array[1] = 6; • array[2] = 8; • What is the type of array? • What is the type of array[2]? 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 Swap(help with project) 1 2 3 4 5 14 2D Arrays(hint for project) • int twoD = new int[3][4] 1 2 3 1 3 5 2 1 7 3 9 7 2 8 5 4 5 row column 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 Selection Sort 4 7 3 9 6 2 8 1 2 7 3 9 6 4 8 2 2 3 7 9 6 4 8 17 Bubble Sort 4 7 5 9 2 3 8 4 5 7 9 2 3 8 4 5 7 2 9 3 8 4 5 7 2 3 9 8 2 3 8 9 18 Friday • Lab 7 • Sorting Algorithms...
View Full 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