Java solution of task 1 of 2