Java algorithm hundred money buy hundred chicken problem

Source: Internet
Author: User
Title: Rooster 5 Text Money One, hen 3 money A, Chick 3 only a penny,
Buy 100 chickens with 100 cents, among them cocks, hens, chickens all must have, ask the rooster, hen, chicken to buy how many only just to make up 100 text money.
Solution: Set, Rooster x only, hen y only, chick Z only.
x+y+z=100
5x+3y+1/3z=100
(0<x<20) (0<y<33)
We use the enumeration method
The code is as follows:
public class teststatic{
public static void Main (string[] args) {
int x;
int y;
int z;
for (x=0;x<20;x++) {
for (y=0;y<33;y++) {
Z=100-x-y;
if (5 x+3y+z/3==100&&z%3==0) {
System.out.println ("Rooster:" +x+ "hen:" +y+ "Chick" +z);
}
}
}
}
}

Java algorithm hundred money buy hundred chicken problem

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.