Java programs to solve a math problem about switches