codegen: handle exceptions of a method
[mate.git] / tests / WhileArray1.java
1 package tests;
2
3 public class WhileArray1 {
4         public char arr[] = new char[10];
5
6         public static void main(String args[]) {
7                 WhileArray1 a = new WhileArray1();
8                 WhileArray1 b = new WhileArray1();
9                 for (int i = 0; i < 10; i++) {
10                         a.arr[i] = b.arr[i] = (char) i;
11                 }
12                 System.out.printf("success? %d\n", equal(a, b, 10) ? 1 : 0);
13
14                 for (int i = 0; i < 10; i++) {
15                         b.arr[i] = (char) i;
16                         a.arr[i] = (char) (b.arr[i] + 2);
17                 }
18                 System.out.printf("success? %d\n", equal(a, b, 10) ? 1 : 0);
19         }
20
21         public static boolean equal(WhileArray1 a, WhileArray1 b, int len) {
22                 /* stolen from the equals implementation of java.lang.String of
23                  * GNU Classpath */
24                 int x = 0, y = 0;
25                 while (--len >= 0) {
26                         System.out.printf("idx: x: %d, y: %d\n", x, y);
27                         if (a.arr[x++] != b.arr[y++]) {
28                                 return false;
29                         }
30                 }
31                 return true;
32         }
33 }