CIS110203 Intro to Computer Science Lab - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

CIS110203 Intro to Computer Science Lab

Description:

s = new String[ ]{'hi', 'hello', 'hey', 'howdy'}; s spot on stack holds ... hi' is in spot 0, 'hello' in spot 1, 'hey' in spot 2, 'howdy' in spot 3. Arrays ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 10
Provided by: cat
Category:

less

Transcript and Presenter's Notes

Title: CIS110203 Intro to Computer Science Lab


1
CIS110-203Intro to Computer Science Lab 9
  • TA Catherine Stocker
  • Mentor Jay Fiddelman
  • University of Pennsylvania
  • 1 November 2007

2
Todays Agenda
  • Sit in your pair programming groups!
  • General Stuff
  • Arrays
  • Lab Work

3
Monitors
  • Turn em off

4
General Stuff
  • How was the test?
  • If you feel like youre falling behind, please
    come talk to me. Also
  • Go to office hours (mine are Weds 2-4).
  • Go to the free tutoring.
  • You can even email me privately and ask me to
    cover something you didnt understand from class.
  • Whatever you do, dont cheat!
  • What can I do in lab to help?

5
Arrays
  • Ways to create
  • String s
  • s spot on stack is null
  • String s new String4
  • OR
  • String s
  • s new String4
  • s spot on stack holds memory address. Heap
    allocates 4 spots, each big enough to hold a
    String.
  • String s hi, hello, hey, howdy
  • OR
  • String s new String hi, hello,
    hey, howdy
  • OR
  • String s
  • s new String hi, hello, hey,
    howdy
  • s spot on stack holds memory address. Heap
    allocates 4 spots, each big enough to hold a
    String. hi is in spot 0, hello in spot 1,
    hey in spot 2, howdy in spot 3

6
Arrays
  • Ways to NOT create
  • String4 s
  • String s new String
  • String s
  • s String4
  • String s new Stringhi, hello, hey,
    howdy
  • String s
  • s hi, hello, hey, howdy
  • String s
  • s new String4hi, hello, hey,
    howdy
  • Lots more

7
Arrays
  • Some things to understand
  • Very useful, compact way to handle a lot of
    variables
  • Even better if you want to do the same thing to
    all of them.
  • Arrays are homogeneous
  • All data stored in them must be of the same type
  • Arrays are indexed 0 to length-1
  • Dont forget to use for(int i0 ilta.length i)
    or you will get an Index out of Bounds exception
  • Indexes can be any int expression
  • 5, c (int variable), c2, x.getVal() (if getVal
    returns an int), etc
  • Can get passed to and from methods
  • public int arrayMethod(double a)
  • Arrays are reference types (i.e. like objects, a
    memory address is stored on stack), so does
    what

8
Lab Work
  • Break into the same groups, different pairs
  • Arrays of Primitives http//www.seas.upenn.edu/c
    se1xx/projects/Arrays/ArraysOfPrimitives/
  • Array of Objects
  • http//www.seas.upenn.edu/cse1xx/projects/Arrays
    /ArrayOfObjects/
  • Submit both.
  • Ok to finish on own or with partner.
  • Each person submits code.
  • Comments on top should cite all authors.

9
Later
  • Come talk to me if you need help!
Write a Comment
User Comments (0)
About PowerShow.com