Multi-solution to the same cage problem of chicken and rabbit

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.