Update Problem2.java

updated the code with comments.