add classic for loop java solution for problem 2