adding algo in java