11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.

Slides:



Advertisements
Similar presentations
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Advertisements

Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
Senem KUMOVA METİN CS FALL 1 ARRAYS && SORTING && STRINGS CHAPTER 6 cont.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 10 2D Arrays.
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
Programming with Collections Collections in Java Using Arrays Week 9.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
1 2-D Arrays Overview l Why do we need Multi-dimensional array l 2-D array declaration l Accessing elements of a 2-D array l Declaration using Initializer.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Multiple-Subscripted Array
C++ for Engineers and Scientists Third Edition
Building Java Programs Chapter 7.5
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
Arrays. Arrays in Java  Arrays in Java are objects.  Like all objects are created with the new keyword.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
AP Comp Sci A Chapter 12 - Arrays. Ch 12 Goals: Goals: Declare and create arrays Declare and create arrays Access elements in arrays Access elements in.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Chapter 7 Arrays. A 12-element array Declaring and Creating Arrays Arrays are objects that occupy memory Created dynamically with keyword new int c[]
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Arrays Array – Group of contiguous memory locations Each memory location has same name Each memory location has same type.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Chapter 4 Practice cont.. Practice with nested loops 1.What will be the output of the following program segment: 1.for (int i = 1; i
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
Arrays. Collections We would like to be able to keep lots of information at once Example: Keep all the students in the class Grade each one without writing.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
The median again The steps of our algorithm: Read the size of the list, N. Declare and instantiate an array of integers, "list". Read the elements of list.
Arrays Dr. Jose Annunziato. Arrays Up to this point we have been working with individual primitive data types Arrays allow working with multiple instances.
Get Longest Run Index (FR) public int getLongestRunIndex(int []values) { int maxRunStart = -1, maxRunLength = 1; int runStart = 0, runLength = 1; for(int.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
Two Dimensional Arrays Found in chapter 8, Section 8.9.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Chapter 8 Slides from GaddisText Arrays of more than 1 dimension.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
© 2006 Pearson Addison-Wesley. All rights reserved Arrays of Greater Dimension One-dimensional arrays are linear containers. Multi-dimensional Arrays.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
Arrays. Arrays are objects that help us organize large amounts of information.
 2005 Pearson Education, Inc. All rights reserved Arrays.
Asserting Java © Rick Mercer Chapter 7 The Java Array Object.
© Rick Mercer Chapter 7 The Java Array Object.  Some variables store precisely one value: a double stores one floating-point number a double stores one.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Chapter 4 Section 1 Organizing Data into Matrices.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Chapter 8 Arrays and the ArrayList Class Multi-Dimensional Arrays.
Two-Dimensional Arrays
Two Dimensional Array Mr. Jacobs.
Chapter 13 Vector of Vectors (2D Arrays)
Chapter 7 The Java Array Object © Rick Mercer.
Computing Fundamentals with C++
Multi-Dimensional Arrays
Chapter 6 - Arrays Outline Multiple-Subscripted Arrays.
Presentation transcript:

11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer

11-2 Two-Dimensional Arrays  Data is sometimes conveniently viewed as tabular data ( in rows and columns) Quiz Quiz

11-3 Declaring Two-Dimensional Arrays  This data can be represented by an array of arrays  General Form type [][] identifier = new type [ rows ][ columns ] type [][] identifier = new type [ rows ][ columns ] type: a primitive type or reference type like String type: a primitive type or reference type like String identifier: reference to the two-dimensional array identifier: reference to the two-dimensional array rows: the number of rows allowed rows: the number of rows allowed columns: the number of columns in each row columns: the number of columns in each row  Example where all 80 elements are 0 int[][] quiz = new int[8][10];

11-4 Referencing individual elements in a 2-D array  Reference to an element of a two-dimensional array requires two subscripts ( row and column) identifier [ row ] [ column ] identifier [ row ] [ column ]  Each subscript must be bracketed individually — [ row, column ] is an error — Examples: quiz[0][0] = 76; quiz[1][1] = 91; int sum = quiz[3][4] + quiz[6][7]; quiz[7][9]++;

11-5 Can use array initializers Each of the 10 arrays has 8 integer elements int[][] quiz = { { 76, 82, 78, 85, 56, 72, 84, 92 }, { 86, 91, 92, 100, 48, 68, 92, 78 }, { 76, 82, 48, 95, 76, 72, 78, 92 }, { 86, 91, 78, 73, 48, 98, 90, 78 }, { 76, 82, 78, 35, 56, 72, 84, 92 }, { 86, 100, 92, 100, 48, 68, 92, 68 }, { 76, 82, 48, 65, 76, 72, 78, 94 }, { 86, 91, 78, 0, 48, 98, 90, 76 }, { 76, 82, 48, 95, 76, 72, 78, 92 }, { 100, 92, 100, 100, 86, 92, 98, 99 } }; assertEquals(76, quiz[0][0]); // upper left assertEquals(100, quiz[5][3]); // near middle assertEquals(99, quiz[9][7]); // lower right

11-6 Can ask for rows and columns assertEquals(10, quiz.length); // rows assertEquals(8, quiz[0].length); // columns assertEquals(8, quiz[7].length); // columns

11-7 Display elements row by row // Example of row by row processing for (int row = 0; row < quiz.length; row++) { // Display one row for (int col = 0; col < quiz[0].length; col++) { // Display each column of each row System.out.print(quiz[row][col] + " "); } System.out.println(); } Output

11-8 Other example code  See Chapter 11 for more examples of row by row processing and column by column processing using nested for loops  Continue code demo with class Matrix