Two-dimensional and Jagged Arrays - Computer Science
Two-dimensional Array
Jagged Array
Simple Application - Courses and Grades
Two-dimensional and Jagged Arrays
Mitsu Ogihara
Department of Computer Science University of Miami
1 / 23
Two-dimensional Array
Table of Contents
Jagged Array
Simple Application - Courses and Grades
1 Two-dimensional Array 2 Jagged Array 3 Simple Application - Courses and Grades
2 / 23
Two-dimensional Array
Jagged Array
Two Dimensional Arrays
Simple Application - Courses and Grades
Arrays with double indices ? ? ? Imagine a rectangular table of data or a matrix
To declare, use two pairs of rackets, e.g., double[][] twoDArray = new double[8][11];
We might be tempted to consider this as (double[])[], but in reality the order is reversed
If only the first index is fixed, it can be treated a one-dimensional array, e.g., for each integer, say j (within the range), twoDArray[j] is a one-dimensional double array
3 / 23
Two-dimensional Array
Read Data from File
Jagged Array
Simple Application - Courses and Grades
Read data from a file into a two-dimensional array The first two tokens in the file are the dimensions of the array Then the data elements follow, row-wise The file name is given as args[ 0 ]
4 / 23
Two-dimensional Array
Jagged Array
The Code: TwoDData.java
Simple Application - Courses and Grades
1 import java.util.*;
2 import java.io.*;
3
4 public class TwoDData {
5
public static void main( String[] args )
6
throws FileNotFoundException {
7
8
Scanner fileScanner = new Scanner( new File( args[ 0 ] ) );
9
int nRows = fileScanner.nextInt();
10
int nCols = fileScanner.nextInt();
11
double[][] data = new double[ nRows ][ nCols ];
12
for ( int i = 0; i < nRows; i ++ ) {
13
for ( int j = 0; j < nCols; j ++ ) {
14
data[ i ][ j ] = fileScanner.nextDouble();
15
}
16
}
The main method throws FileNotFoundException when the file specified in args[ 0 ] does not exist
5 / 23
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- two dimensional arrays semantic scholar
- chapter 8 multidimensional arrays southeastern louisiana university
- recursion and 2 d arrays inspiring innovation
- 2 dimensional arrays example trinity college dublin
- technical note no 114 java 2d arrays
- 2d array ds
- java game programming 2d graphics and animation
- two dimensional arrays drew university
- 2 d arrays motivating example 2 1 two dimensional arrays
- unit 8 2d arrays github pages
Related searches
- initialize two dimensional array java
- two dimensional array java
- java two dimensional array initialization
- two dimensional array in powershell
- two dimensional arraylist java
- c two dimensional arraylist
- javascript two dimensional array example
- two dimensional array example
- two dimensional arrays in javascript
- javascript two dimensional array
- javascript sort two dimensional array
- javascript two dimensional array push