百钱百鸡
//百钱买百鸡: //公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱, //用100文钱买一百只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱。
Buychicken(); private static void Buychicken() { int i,j,k; int num = 100; for (i=0;i <= (num/5);i++){ for (j=0;j <= (num/3);j++){ for (k=0; k <= (num/3);k++){ if (i*5 + j*3 + k*3 == num && i != 0 && j != 0 && k != 0){ System.out.printf("公鸡买%d只,母鸡买%d只,小鸡买%d只",i,j,k); } } } } }
本文来自博客园,作者:xiaoyongdata(微信号:xiaoyongdata),转载请注明原文链接:https://www.cnblogs.com/xiaoyongdata/p/16267439.html