/
Two Dimensional Arrays Two Dimensional Arrays

Two Dimensional Arrays - PowerPoint Presentation

pasty-toler
pasty-toler . @pasty-toler
Follow
392 views
Uploaded On 2016-03-05

Two Dimensional Arrays - PPT Presentation

public class TwoDArray private int rows private int cols private String myArray public TwoDArrayint numRows int numCols rows numRows cols numCols ID: 242638

row col rows int col row int rows cols public private myarray diameter circle void final circleat testtwodimarray dimensional

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Two Dimensional Arrays" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Two Dimensional ArraysSlide2
Slide3
Slide4
Slide5

public class

TwoDArray

{

private

int

rows;

private

int cols; private String[][] myArray; public TwoDArray(int numRows, int numCols) { rows = numRows; cols = numCols; myArray = new String[rows][cols]; } public void fillArray() { for (int row=0; row<rows; row++) { for (int col=0; col<cols; col++) { myArray[row][col] = row + "," + col; } } } public void printArray() { for (int row=0; row<rows; row++) { for (int col=0; col<cols; col++) { System.out.print("myArray[" + row + "][" + col + "] = " + myArray[row][col] + "\t"); } System.out.println(); } } }Slide6
Slide7

public class

TestTwoDimArray

{

private Circle[][]

circleArray

;

private final

int rows = 10; private final int cols = 10; private final int diameter = 40; /** * Creates an empty 2-dimensional Circle array. */ public TestTwoDimArray() { circleArray = new Circle[rows][cols]; } /** * Fill the array with circles. */ public void fillArray() { for(int row = 0; row < rows; row++) { for(int col = 0; col < cols; col++) { circleArray[row][col] = new Circle(diameter, col * diameter, row * diameter); } } }