CMSC 150 MULTI-DIMENSIONAL ARRAYS CS 150: Mon 27 Feb 2012.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

1 Arrays, Strings and Collections [1] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
Introduction to Java 2 Programming Lecture 5 Array and Collections.
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
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.
Image Processing … computing with and about data, … where "data" includes the values and relative locations of the colors that make up an image.
ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Senem KUMOVA METİN CS FALL 1 ARRAYS && SORTING && STRINGS CHAPTER 6 cont.
Arrays in JAVA CS 340 Software Design Muhammad Talha.
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
Arrays CS Feb Announcements Exam 1 Grades on Blackboard Project 2 scores: end of Class Project 4, due date:20 th Feb –Snakes & Ladders Game.
Arrays. A group of data with same type stored under one variable. It is assumed that elements in that group are ordered in series. In C# language arrays.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
Original image: 512 pixels by 512 pixels. Probe is the size of 1 pixel. Picture is sampled at every pixel ( samples taken)
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
CSC 142 J 1 CSC 142 Arrays [Reading: chapter 10].
Java Unit 9: Arrays Declaring and Processing Arrays.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
CSC – Java Programming II Lecture 9 January 30, 2002.
Program structure Four different storage-class specifications: –Automatic (auto): local to a function, normally declared variables are automatic. Does.
CSC1401 Viewing a picture as a 2D image - 1. Review from the last week We used a getPixels() to get all of the pixels of a picture But this has been somewhat.
1 Lecture # 4. * An array is a group of contiguous or related data items that share a common name. * Each value is stored at a specific position * Position.
ArrayList, Multidimensional Arrays
JAVA Arrays. Objectives Be able to declare and initialize arrays Be able to conceptualize (draw) how arrays are represented in computer memory. Be able.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
Pictures Looping through pixels.. Lab Review (1) Objects  Instantiated from Class  Turtle myTut = new Turtle(myWorld);  new operator creates an instance.
Java SE 8 for Programmers, Third Edition
ARRAYS Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall
2D-Arrays Quratulain. Learning Objectives Two-dimensional arrays Declaration Initialization Applications.
Georgia Institute of Technology Movies part 5 Barb Ericson Georgia Institute of Technology April 2006.
Two –Dimensional Arrays Mrs. C. Furman Java Programming November 19, 2008.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
Multidimensional Arrays. 2 Two Dimensional Arrays Two dimensional arrays. n Table of grades for each student on various exams. n Table of data for each.
CSC1401 Classes - 1. Learning Goals Computing concepts Identifying objects and classes Declaring a class Declaring fields Default field values.
DT249-Information Systems Research Practice Programming Revision Lecture 2 Lecturer: Patrick Browne.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 5 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
© 2006 Pearson Addison-Wesley. All rights reserved1-1 Chapter 1 Java Fundamentals - Arrays and References (updated by Dan Fleck)
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington 2D arrays COMP 102 # T1.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
Chapter 10 Arrays. Learning Java through Alice © Daly and Wrigley Objectives Declare and use arrays in programs. Access array elements within an array.
Lecture 07. Do not have to create an array while declaring array variable [] variable_name; int [] prime; int prime[]; Both syntaxes are equivalent No.
CS 180 Recitation 7 Arrays. Used to store similar values or objects. An array is an indexed collection of data values of the same type. Arrays are the.
Copyright © Curt Hill Further Picture Manipulation Considering position.
Arrays. Arrays as ADTs An array is an Abstract Data Type –The array type has a set of values The values are all the possible arrays –The array type has.
CiS 260: App Dev I. 2 Introduction to Arrays n An array is an object that contains a collection of components (_________) of the same data type. n For.
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
 Introducing Arrays  Declaring Array Variables, Creating Arrays, and Initializing Arrays  Copying Arrays  Multidimensional Arrays  Search and Sorting.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
CMSC 150 ARRAYS CS 150: Fri 10 Feb Motivation  Consider a list of your contact addresses: String Zero = String.
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
Object Oriented Programming Lecture 2: BallWorld.
using System; namespace Demo01 { class Program
Data Structures Array - Code.
CS Week 8 Jim Williams, PhD.
Decision statements. - They can use logic to arrive at desired results
Multidimensional Arrays
Code Animation Examples
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Arrays in Java.
Ps Module 7 – Part II 2D Arrays and LISTS 5/26/2019 CSE 1321 Module 7.
Presentation transcript:

CMSC 150 MULTI-DIMENSIONAL ARRAYS CS 150: Mon 27 Feb 2012

Motivation  A digital image is a two- dimensional collection of pixels (picture elements)  Each pixel has an associated color (green, brown, pink, yellow)  Taken collectively, the pixels form the image

Motivation

pixel

2D Array  can be primitive or class type  S yntax:  type[][] variableName;  type[][] variableName = new type[numRows][numCols];  Examples: Color[][] pixels = new Color[100][256]; boolean[][] missingTeeth = new boolean[2][16]; String[][] firstLastNames = new String[NUM_STUDENTS][2];

public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } In Memory myArray null

In Memory 0x12AB79 [0][0] [0][1] [0][2] public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [1][0] [1][1] [1][2]

In Memory 0x12AB79 [0][0] [0][1] [0][2] public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [1][0] [1][1] [1][2] row 0 row 1

In Memory 0x12AB79 77 public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2]

In Memory 0x12AB public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2]

In Memory 0x12AB public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2]

In Memory 0x12AB public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] 154

In Memory 0x12AB public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2]

In Memory 0x12AB public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2]

In Memory 0x12AB public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] myArray[0] myArray is an int[][] myArray[0] is an int[] myArray[0][0] is an int myArray is an int[][] myArray[0] is an int[] myArray[0][0] is an int

In Memory 0x12AB public class 2DArrayExample { public static void main(String[] args) { int[][] myArray; myArray = new int[2][3]; myArray[0][0] = 77; myArray[0][1] = 42; myArray[0][2] = 101; myArray[1][0] = ; myArray[1][1] = ; myArray[1][2] = ; } myArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] myArray[1] myArray is an int[][] myArray[1] is an int[] myArray[1][0] is an int myArray is an int[][] myArray[1] is an int[] myArray[1][0] is an int

In Memory 0x12AB79 public class 2DArrayExample { public static void main(String[] args) { String[][] strArray; strArray = new String[2][3]; for (int i = 0; i < strArray.length; i++) { for (int j = 0; j < strArray[i].length; j++) { strArray[i][j] = new String((i+1) + “ and “); } strArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] 0x33DB26 0x33DC01 0x33DD25 0x33DE04 0x33DE29 0x33DF22

In Memory 0x12AB79 public class 2DArrayExample { public static void main(String[] args) { String[][] strArray; strArray = new String[2][3]; for (int i = 0; i < strArray.length; i++) { for (int j = 0; j < strArray[i].length; j++) { strArray[i][j] = new String((i+1) + “ and “); } strArray [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] 0x33DB26 0x33DC01 0x33DD25 0x33DE04 0x33DE29 0x33DF22 # rows # cols

Managing 2D Arrays  Typically use nested for loops: int[][] randomNumbers = int[1024][2048]; for (int i = 0; i < randomNumbers.length; i++) { for (int j = 0; j < randomNumbers[i].length; j++) { randomNumbers[i][j] = generator.nextInt(10000); }

Managing 2D Arrays  Typically use nested for loops: int[][] randomNumbers = int[1024][2048]; for (int i = 0; i < randomNumbers.length; i++) { for (int j = 0; j < randomNumbers[i].length; j++) { randomNumbers[i][j] = generator.nextInt(10000); } int numberOfOdds = 0; for (int i = 0; i < randomNumbers.length; i++) { for (int j = 0; j < randomNumbers[i].length; j++) { if ( randomNumbers[i][j] % 2 != 0 ) { numberOfOdds++; } }

Let’s Try Some… Photo by Gary Mueller, from (Cornell Laboratory of Ornithology)