Final solutions for java, c++

both could be more efficient, solutions is correct though