Large number power algorithm for a number in java