Array Example

Array Example - int cr = new int[4] String dr = new...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 public class ArrayTalk{ public static void main(String[] args){ int[][] ar = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}} System.out.println("rows = " + ar.length) System.out.println("cols = " + ar[0].length) System.out.println(ar[1][2]) int[][] br = {{1,2}, {3,4,5,6}, {7,8,9}, {10,11,12}} System.out.println("rows = " + br.length) System.out.println("cols in 1st row = " + br[0].length) System.out.println("cols in 2nd row = " + br[1].length) System.out.println(br[0][1])
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int cr = new int[4] String dr = new String[3][2] dr[0][0] = new String("Java") System.out.println(dr[0][1]) System.out.println(dr[0][0]) TwoVector er = new TwoVector[3] for(int cols = 0 cols<3 cols++){ er[cols] = new TwoVector[cols+1] } er[0][0] = new TwoVector(2.0,3.1) er[1][0] = new TwoVector(-1.0,0.0) er[1][1] = new TwoVector(2,2) er[2][0] = new TwoVector(-3,4) System.out.println(er[1][0]) } }...
View Full Document

Ask a homework question - tutors are online