Multi-solution to the same cage problem of chicken and rabbit
I still remember that there was a question about the cage of chicken and rabbit in a running male, saying that the chicken and rabbit were in the same cage, with a total of 35 heads and 94 legs. How many chickens were there? How many rabbits are there?
Today, I want to use the recently learned java knowledge to solve this question. Of course, I calculated the result of the question. to verify whether the output is correct or not, I will not talk much about it, direct code:
In fact, we can see that the code is getting simpler and simpler. In the end, we even gave up using loops to complete the process, which completely turned into a mathematical formula. But when I was just doing this, it took me two hours to figure out my ideas, and then I made it easier.
The idea is very important. If you want to accomplish something on your own, you must have a clear idea. This is just a very simple question, but I have learned a lot.