(java) Solve problem 5
(java) Add comment and complexity in problem 5