Solving simple problems with Java