/Users/lyon/j4p/src/bookExamples/ch08ArraysAndVectors/array/Array.java
|
1 package bookExamples.ch08ArraysAndVectors.array;
2
3 public class Array {
4 int i[][] = new int[10][10];
5
6 public static void main(String args[]) {
7 Array a = new Array();
8 a.setMainDiagonal(1);
9 a.print();
10 dimTest();
11 }
12
13 public static void dimTest() {
14 int ia[][] = new int[10][10];
15 int ib[] = new int[10];
16 Object o = ia;
17 if (o instanceof int[][])
18 System.out.println("o is 2d");
19 if (o instanceof int[])
20 System.out.println("o is 1d");
21 }
22
23 public void setMainDiagonal(int s) {
24 for (int x = 0; x < i.length; x++)
25 for (int y = 0; y < i[0].length; y++)
26 if (x == y)
27 i[x][y] = s;
28 }
29
30 public void print() {
31 for (int x = 0; x < i.length; x++) {
32 for (int y = i[0].length - 1; y >= 0; y--)
33 System.out.print(i[x][y] + " ");
34 System.out.println();
35 }
36 }
37 }