paul@67 | 1 | public class ArrayTest { |
paul@67 | 2 | public int[] array; |
paul@67 | 3 | |
paul@67 | 4 | public ArrayTest(int size) { |
paul@67 | 5 | array = new int[size]; |
paul@67 | 6 | } |
paul@67 | 7 | |
paul@67 | 8 | public int get(int index) { |
paul@67 | 9 | return array[index]; |
paul@67 | 10 | } |
paul@133 | 11 | |
paul@133 | 12 | public static void main(String[] args) { |
paul@133 | 13 | ArrayTest test = new ArrayTest(10); |
paul@133 | 14 | if (test.array.length != 10) { |
paul@133 | 15 | System.err.println("test.array.length failed!"); |
paul@133 | 16 | } else { |
paul@133 | 17 | System.out.println("test.array.length correct: " + test.array.length); |
paul@133 | 18 | } |
paul@133 | 19 | for (int i = 0; i < test.array.length; i++) { |
paul@133 | 20 | test.array[i] = i + 10; |
paul@133 | 21 | } |
paul@133 | 22 | for (int j = 0; j < test.array.length; j++) { |
paul@133 | 23 | if (test.get(j) != j + 10) { |
paul@133 | 24 | System.err.println("test.get(" + j + ") failed!"); |
paul@133 | 25 | } else { |
paul@133 | 26 | System.out.println("test.get(" + j + ") correct: " + test.get(j)); |
paul@133 | 27 | } |
paul@133 | 28 | } |
paul@133 | 29 | } |
paul@67 | 30 | } |
paul@133 | 31 | |
paul@133 | 32 | // vim: tabstop=4 expandtab shiftwidth=4 |