// No gotos
// Assigning to variables only once
// Using no local variables
// No return value
// One arg
// No if
public class SumOdd4567 {
static int[] data = {1, 3, 4, 5, 6, 123, 4, 32, 1, 7, 66, 435, 23, 112,
34, 5, 6};
public static void main(String[] args)
{
SumOddAll first;
(first = new SumOddAll(data)).add(0);
System.out.println("sum = " + first.sum);
}
}
class SumOddAll {
int[] ints;
int sum;
int x;
SumOddAll next;
SumOddAll(int[] _ints) { ints = _ints; }
SumOddAll(SumOddAll prev) { ints = prev.ints; }
synchronized void add(int ix)
{
try {
x = ints[ix];
next = new SumOddAll(this);
next.add(ix + 1);
sum = next.sum + (x & 1) * x;
}
catch(Exception e) {
sum = 0;
}
}
}