Started solving Problem 3 in java