Hundred-wen buys hundred chicken

Source: Internet
Author: User

public class Test04 {
public static void Main (string[] args) {
int x,y,z;//x represents the number of cocks, Y is the number of hens, and Z represents the number of chickens.
for (x=1;x<20;x++) {//Because only 100 money, up to buy 20 cocks, but all buy cocks can not reach 100
for (y=1;y<33;y++) {//Because only 100 money, up to buy 33 cocks, but all buy hens will not reach 100
if (x*5+y*3<=100) {//x*5+y*3 equals money to buy cocks and hens cannot exceed 100
z=3* (100-(x*5+y*3))///Get rid of the money that buys the rooster, the hen is the money that buys the chicken,
The number of chickens bought is equal to the money of the chickens multiplied by 3
if (x+y+z==100) {//The number of all chickens must be equal to 100.
System.out.print ("The number of cocks, hens, chickens are:" +x);
System.out.print ("+y");
System.out.println ("+z");
}
}
}
}
}
}

Hundred-wen buys hundred chicken

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.