Converted main to java, and started working on the solve function.