Problem 2 completed in Java
Problem 2 completed in Python