Solved in Java