[PDF] [PDF] Topic 26 Two Dimensional Arrays - UT Austin Computer Science

Jeffery Ullman Based on slides for Building Java Programs by Reges/Stepp, found at Write a method to find the max value in a 2d array of ints Write a 



Previous PDF Next PDF





[PDF] Two-Dimensional Arrays

Two-dimensional (2D) arrays are indexed by two subscripts, one for the row and one for the column Each element in the 2D array must by the same type, either a primitive type or object type



[PDF] Chapter 7 Multidimensional Arrays

Listing 7 1 gives an example with a method that returns the sum of all the elements in a matrix LISTING 7 1 PassTwoDimensionalArray java (Page 240) import 



[PDF] Multidimensional Arrays

In Java, each subscript must be enclosed in a pair of square brackets • You can also use 8 4 Passing Two-Dimensional Arrays to Methods • You can pass a 



[PDF] CS 106A, Lecture 17 2D Arrays and Images

Java infers the array length The class Arrays in package java util has useful methods for A 2D array is an array where every element is itself an array



[PDF] 2D Array Exercise

Practice using two dimensional arrays to input and output data in a tabular format A Simple 2D TwoDArray java for (int col=0; col < table[row] length; col++)



[PDF] Topic 26 Two Dimensional Arrays - UT Austin Computer Science

Jeffery Ullman Based on slides for Building Java Programs by Reges/Stepp, found at Write a method to find the max value in a 2d array of ints Write a 



[PDF] Unit 8: 2D Arrays - Long Nguyen

1) Building Java Programs: A Back to Basics Approach by Stuart Reges 2D Arrays A two-dimensional (2D) array has rows and columns A row has horizontal elements 2) For each k, where 0



[PDF] 2D Array Problems - Rose-Hulman

This code prints out a two dimensional array of integers The function returns the distance between the of the pair in the map of java they have to be typed



[PDF] Using Two-Dimensional Arrays

The new, five-floor Java Hotel features a free continental breakfast and, at The people who do serious Java like to think of a two-dimensional array as an array of with an array of objects, you're taking advantage of methods that are already

[PDF] 2d dft example

[PDF] 2d dft in digital image processing

[PDF] 2d discrete fourier transform matlab code

[PDF] 2d fft algorithm

[PDF] 2d fft image matlab

[PDF] 2d fft of image

[PDF] 2d fft radar

[PDF] 2d fft symmetry

[PDF] 2d fftshift

[PDF] 2d fourier transform examples

[PDF] 2d fourier transform mathematica

[PDF] 2d fourier transform properties

[PDF] 2d heat equation derivation

[PDF] 2d image to 3d model python

[PDF] 2d picture to 3d model

Topic 26

Two Dimensional Arrays

"Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable techniques to solve it." -Alfred Aho and Jeffery Ullman Based on slides for Building Java Programs by Reges/Stepp, found at

2D Arrays in Java

Arrays with multiple dimensions may be

declared and used int[][] mat = new int[3][4]; the number of pairs of square brackets indicates the dimension of the array. by convention, in a 2D array the first number indicates the row and the second the column 2

Two Dimensional Arrays

0 1 2 3 column

0 1 2 row 0000 0000 0000 This is our abstract picture of the 2D array and treating it this way is acceptable. (actual implementation is different) mat[2][1] = 12; 3

What is What?

int[][] mat = new int[10][12]; // mat is a reference to the whole 2d array // mat[0] or mat[r] are references to a single row // mat[0][1] or mat[r][c]are references to // single elements // no way to refer to a single column // mat.length is the number of rows // mat[0].length is the number of columns // in row 0. 4

2D Array Problems

Write a method to find the max value in a 2d array of ints Write a method that finds the sum of values in each column of a 2d array of doubles

Write a method to print out the elements of a 2d

array of ints in row order. row 0, then row 1, then row 2 ...

Write a method to print out the elements of a 2d

array of ints in column order column 0, then column 1, then column 2 ... 5

Clicker 1

What is output by the following code?

String[][] strTable= new String[5][8];

System.out.print(strTable.length+ " ");

System.out.print(strTable[0].length + " ");

A.40 0 0

B.8 5 0

C.5 8 0

D.5 8 then a runtime error occurs

E.No output due to a syntax error.

6

Use of Two Dimensional Arrays

2D arrays are often used when I need a

table of data or want to represent things that have 2 dimensions.

For instance an area of a simulation

7

Example of using a 2D array

Conway's Game of Life

a cellular automaton designed by John Conway, a mathematician not really a game a simulation takes place on a 2d grid each element of the grid is occupied or empty 8

Simulation

Select pattern from menu

Select region in large area with mouse by

pressing the control key and left click at the same time

Select the paste button

9

Generation 0

0 1 2 3 4 5

0 1 2 3 * indicates occupied, . indicates empty 10 Or

0 1 2 3 4 5

0 1 2 3 11

Generation 1

0 1 2 3 4 5

0 1 2 3 * indicates occupied, . indicates empty 12

Or , Generation 1

0 1 2 3 4 5

0 1 2 3 13

Rules of the Game

If a cell is occupied in this generation.

it survives if it has 2 or 3 neighbors in this generation it dies if it has 0 or 1 neighbors in this generation it dies if it has 4 or more neighbors in this generation

If a cell is unoccupied in this generation.

there is a birth if it has exactly 3 neighboring cells that are occupied in this generation

Neighboring cells are up, down, left, right,

and diagonal. In general a cell has 8 neighboring cells 14

Clicker 2

Implement a program to run the

simulation

What data type do you want to use for

the elements of the 2d array?

A.String

B.char

C.int

D.boolean

E.double

15

Clicker 3

Do you want to use a

buffer zone on the edges? A.No B.Yes 16quotesdbs_dbs4.pdfusesText_7