Multidimensional Arrays Histograms CSC 1401: Introduction to Programming with Java Week 11 – Lecture 1 Wanda M. Kunkle.

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

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.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Arrays part 3 Multidimensional arrays, odds & ends.
Converting Between Numbers and Characters CSC 1401: Introduction to Programming with Java Week 4 – Lecture 3 Wanda M. Kunkle.
Repetition Structures: Nested Loops CSC 1401: Introduction to Programming with Java Week 6 – Lecture 2 Wanda M. Kunkle.
More on Arrays CSC 1401: Introduction to Programming with Java Week 10 – Lectures 2 & 3 Wanda M. Kunkle.
Boolean Expressions Conditional Statements & Expressions CSC 1401: Introduction to Programming with Java Lecture 4 – Part 2 Wanda M. Kunkle.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
©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.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
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.
Repetition Structures: For Loop Constants CSC 1401: Introduction to Programming with Java Week 5 Wanda M. Kunkle.
Repetition Structures: Do-while Loop Random Number Generation CSC 1401: Introduction to Programming with Java Week 6 Wanda M. Kunkle.
Selection Structures: Switch CSC 1401: Introduction to Programming with Java Week 4 – Lecture 1 Wanda M. Kunkle.
Introduction to Arrays CSC 1401: Introduction to Programming with Java Week 10 – Lecture 1 Wanda M. Kunkle.
More on Recursion Averting Program Crashes CSC 1401: Introduction to Programming with Java Week 9 – Lecture 3 Wanda M. Kunkle.
Multidimensional Arrays C++ also allows an array to have more than one dimension. For example, a two-dimensional array consists of a certain number of.
Java Unit 9: Arrays Declaring and Processing Arrays.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Searching Arrays Searching.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Lecture 5: Arrays A way to organize data MIT AITI April 9th, 2005.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Copyright © Curt Hill Multiple Dimension Arrays Extending Java Arrays.
ITI 1120 Lab #9 Slides by: Diana Inkpen and Alan Williams.
1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C arrays ❏ To be able to pass arrays and array elements to functions.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Get Longest Run Index (FR) public int getLongestRunIndex(int []values) { int maxRunStart = -1, maxRunLength = 1; int runStart = 0, runLength = 1; for(int.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Lec 13 Oct 21, 02. Array Initialization in the declaration statement ► int temp[5] = {98, 87, 92, 79,85}; ► char codes[6] = { ‘s’, ’a’, ‘m’, ‘p’, ‘l’,
CSC Programming for Science Lecture 28: Multi-dimensional Arrays.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
1 Arrays of Arrays Quick review … arrays Arrays of arrays ≡ multidimensional array Example: times table Representation in memory Ragged arrays Example:
Arrays Chapter 7. 2 Declaring and Creating Arrays Recall that an array is a collection of elements all of the _____________ Array objects in Java must.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
Arrays. C++ Style Data Structures: Arrays(1) An ordered set (sequence) with a fixed number of elements, all of the same type, where the basic operation.
Two-dimensional Arrays two-dimensional arrays are often used to represent tables of values consisting of data arranged in rows and columns (Fig. 7.16).
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.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Windows Programming Lecture 03. Pointers and Arrays.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline 1 Introduction 2 Arrays 3Declaring Arrays 4Processing Array Contents 5 Multiple-Subscripted.
Arrays Chapter 7.
Two-Dimensional Arrays
multi-dimensional arrays
A simple way to organize data
Multidimensional Arrays
Arrays Chapter 7.
Multidimensional array
Multi-Dimensional Arrays
Presentation transcript:

Multidimensional Arrays Histograms CSC 1401: Introduction to Programming with Java Week 11 – Lecture 1 Wanda M. Kunkle

2 1-Dimensional vs. 2-Dimensional Arrays Recall how we declared and created a 1-D array: Recall how we declared and created a 1-D array: int values[] = new int[5]; int values[] = new int[5]; We declare and create a 2-D array in much the same way: We declare and create a 2-D array in much the same way: int table[][] = new int[10][6]; int table[][] = new int[10][6]; The above Java statement creates a 2-D integer array with 10 rows and 6 columns, essentially a 10 x 6 matrix The above Java statement creates a 2-D integer array with 10 rows and 6 columns, essentially a 10 x 6 matrix Note: The above 2-D array code can also be written: int [][] table = new int [10][6]; Note: The above 2-D array code can also be written: int [][] table = new int [10][6];

3 1-Dimensional Array Recall how we initialized a 1-D array: Recall how we initialized a 1-D array: Initial values known Initial values known values[0] = 25; values[1] = 11; values[2] = 38; values[3] = 3; values[4] = 17; values[0] = 25; values[1] = 11; values[2] = 38; values[3] = 3; values[4] = 17; int values[] = {25, 11, 38, 3, 17}; int values[] = {25, 11, 38, 3, 17};

4 1-Dimensional Array Recall how we initialized a 1-D array: Recall how we initialized a 1-D array: Initial values not known Initial values not known Initialize element contents to 0 to “play it safe” Initialize element contents to 0 to “play it safe” int values[] = new int[5]; for (int i = 0; i < values.length; i++) values[i] = 0; int values[] = new int[5]; for (int i = 0; i < values.length; i++) values[i] = 0; We’ll assign real values to the array later. We’ll assign real values to the array later. The array “knows” how big it is.

5 2-Dimensional Array In Lab 6, we created 2-dimensional figures (triangle, arrow) using nested loops. In Lab 6, we created 2-dimensional figures (triangle, arrow) using nested loops. Similarly, we generally initialize 2- dimensional arrays using nested loops. Similarly, we generally initialize 2- dimensional arrays using nested loops. Code to initialize the 2-D array table to all 0s appears in the next slide. Code to initialize the 2-D array table to all 0s appears in the next slide.

6 2-Dimensional Array Typical initialization routine Typical initialization routine Initialize array elements to 0 Initialize array elements to 0 int[][] table = new int[10][6]; int row, column; for (row = 0; row < 10; row++) for (column = 0; column < 6; column++) table[row][column] = 0; int[][] table = new int[10][6]; int row, column; for (row = 0; row < 10; row++) for (column = 0; column < 6; column++) table[row][column] = 0;

7 2-Dimensional Array Alternate initialization routine Alternate initialization routine Initialize array elements to values specified by the programmer (as in the Tictactoe program in Lab 11 which employs a 3 x 3 character array) Initialize array elements to values specified by the programmer (as in the Tictactoe program in Lab 11 which employs a 3 x 3 character array) char [][] tictac = { {'X', 'X', 'O'}, {' ', 'O', ' '}, {'X', 'O', 'X'} }; char [][] tictac = { {'X', 'X', 'O'}, {' ', 'O', ' '}, {'X', 'O', 'X'} };

8 Sample Program The following program uses 2-D arrays to implement a table showing how interest rates affect bank balances: The following program uses 2-D arrays to implement a table showing how interest rates affect bank balances: InterestTable.java InterestTable.java InterestTable.java

9 Histograms Since Lab 11 employs histograms, I thought it wise to briefly discuss them in case any one of you is not familiar with them. Since Lab 11 employs histograms, I thought it wise to briefly discuss them in case any one of you is not familiar with them. According to the Wikipedia*: According to the Wikipedia*: “In statistics, a histogram is a graphical display of tabulated frequencies. A histogram is the graphical version of a table that shows what proportion of cases fall into each of several or many specified categories.” *This is the definition of a histogram most relevant for Lab 11; this and other definitions can be viewed at: “In statistics, a histogram is a graphical display of tabulated frequencies. A histogram is the graphical version of a table that shows what proportion of cases fall into each of several or many specified categories.” *This is the definition of a histogram most relevant for Lab 11; this and other definitions can be viewed at: displayfrequenciescategories displayfrequenciescategories

10 Die Rolling Simulation A program that simulates the rolls of a die is suitable for graphically displaying frequencies, such as the number of times a 1 is rolled, the number of times a 2 is rolled, etc. A program that simulates the rolls of a die is suitable for graphically displaying frequencies, such as the number of times a 1 is rolled, the number of times a 2 is rolled, etc. A sample program that does just that is: DieRollingSimulation.java A sample program that does just that is: DieRollingSimulation.java DieRollingSimulation.java

11 Lab 11 Now let’s look at how the preceding discussion relates to today’s lab. Now let’s look at how the preceding discussion relates to today’s lab.