Ex192DWksht

Ex192DWksht - 2 myArray[otherArray[4]][0] = myArray[2][0] =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Operation Format Examples Declaration: type name [][]; int myArray[][]; Allocation: name = new type [ rows ][ columns ]; myArray = new int[50][75]; Reading values: x = name [ row ][ column ]; x = myArray[3][7]; Assigning values: name [ row ][ column ] = value; myArray[3][7] = 5; Syntactic sugar: Declare, allocate, and initialize on one line myArray[][] = { {1,2,8}, {3,4,0}, {7,11,10}, {6,5,9}}; otherArray[] = { 7, 3, 1, 8, 2, 4, 9, 5, 6, 0}; This creates the following: myArray ---------------- 1 2 8 3 4 0 7 1 1 10 6 5 9 otherArray ------------- 7 3 1 8 2 4 9 5 6 0 What are the values of the following expressions? myArray[1][2] 0 otherArray[4]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2 myArray[otherArray[4]][0] = myArray[2][0] = 7 myArray[3][0]+1 = 6 + 1 = 7 What does this line do? myArray[3][1]++ myArray ---------------- 1 2 8 3 4 7 1 1 10 6 6 9 What will print out? for(int counter = 0; counter < 3; counter++) for(int counter2 = 0; counter2 < 4; counter2++) System.out.printf("%d, ",myArray[counter2][counter] - 1); System.out.println(); counter counter2 number printed out myArray[0][0]-1 1 myArray[1][0]-1 2 2 6 3 5 1 1 1 1 3 1 2 10 1 3 5 (4) 2 7 2 1-1 2 2 9 2 3 8...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 2

Ex192DWksht - 2 myArray[otherArray[4]][0] = myArray[2][0] =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online