Prefix sum impl in java