Using java to write some methods to solve math problems