adda java solution to problem 22