17-apr02

17-apr02 - array[0] = 5; array[1] = 6; array[2] = 8; What...

Info iconThis 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Announcements Program 4 Due April 23 (that’s 3 weeks!) This is a HARD program Start early Start early Start early
Background image of page 2
3 Program 4 Demo
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Questions?
Background image of page 4
5 Today in COMP 110 More about arrays Info for program 4
Background image of page 5

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

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

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

View Full DocumentRight Arrow Icon
8 Array of Classes Smiley[] smile = new Smiley[3]; 1045 2584 2836 True GREEN 3 False BLUE 1 False CYAN 4
Background 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
Background image of page 9

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

View Full DocumentRight 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; }
Background image of page 10
11 Types int[] array = new int[3];
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

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

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

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

View Full DocumentRight Arrow Icon
Background image of page 16
Background image of page 17

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

View Full DocumentRight Arrow Icon
Background 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 &lt; 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

This note was uploaded on 02/02/2009 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Page1 / 18

17-apr02 - array[0] = 5; array[1] = 6; array[2] = 8; What...

This preview shows document pages 1 - 18. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online