Monkey banana problem in java. Suppose the problem is as given below −.