WUSTL CSE 131 - sp14_3 (29 pages)

Previewing pages 1, 2, 3, 27, 28, 29 of 29 page document View the full content.
View Full Document

sp14_3



Previewing pages 1, 2, 3, 27, 28, 29 of actual document.

View the full content.
View Full Document
View Full Document

sp14_3

169 views


Pages:
29
School:
Washington University in St. Louis
Course:
Cse 131 - Computer Science I
Computer Science I Documents

Unformatted text preview:

Module 3 Arrays Chapter 1 4 Introduction to Programming in Java An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 1 14 19 06 26 24 AM A Foundation for Programming any program you might want to write objects functions and modules graphics sound and image I O arrays store and manipulate huge quantities of data conditionals and loops Math primitive data types text I O assignment statements 2 Arrays Store and manipulate huge quantities of data Examples 52 playing cards in a deck All the students in CSE 131 1 million characters in a book 10 million audio samples in an MP3 file Example question 1 valentine s chocolate problem 2 Output a sorted set of cards 3 Output a shuffled set of cards 3 Many Variables of the Same Type Goal 10 variables of the same type tedious and error prone double a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a0 0 0 a1 0 0 a2 0 0 a3 0 0 a4 0 0 a5 0 0 a6 0 0 a7 0 0 a8 0 0 a9 0 0 a4 3 0 a8 8 0 double x a4 a8 4 Many Variables of the Same Type Goal 10 variables of the same type double a declaration a new double 10 creation a 4 3 0 a 8 8 0 double x a 4 a 8 5 Many Variables of the Same Type Goal 1 million variables of the same type scales to handle large arrays double a new double 1000000 a 123456 3 0 declares creates and initializes in a same sentence a 987654 8 0 double x a 123456 a 987654 6 Arrays in Java Java has special language support for arrays To make an array declare create and initialize it To access entry i of array named a use a i Array indices start at 0 Size of an array a a length int N 10 double a a new double N for int i 0 i N i a i 0 0 size of array declare the array create the array initialize the array all to 0 0 7 Arrays in Java Java has special language support for arrays To make an array declare create and initialize it To access entry i of array named a use a i Array indices start at 0 int N 10 double a a new double N for int i 0 i N i a i 0 0 size of array declare the array create the array initialize the array



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view sp14_3 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view sp14_3 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?