Short Java codes and algorithms for simple problems