用Java编程解决鸡兔同笼的问题

用for循环解决

以“今有雉兔同笼,上有三十五头,下有九十四足,问雉兔各几何?”为例

public class test {
    public static void main(String[] args) {
        int x,y;  //x:鸡  y:兔
        for(x=0;x<=35;x++) {   //遍历鸡的只数
            y=35-x;        //兔的只数等于35 - 鸡
            if(2*x+4*y==94)   //如果鸡和兔的脚总数是94            
                System.out.println("鸡"+x+"只,兔"+y+"只");
               }
    }
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-04-03
/*解: 设兔子有X只,鸡有Y只;
4x+2Y=脚;①
X+Y=头;②
假设鸡只有一只脚,兔子只有2条腿,则
约分:2X+Y=脚/2;③
且 鸡的脚和鸡的头都是1;
由②③得:
X+Y=头;②
2X+Y=脚/2;③
由③-②得到;
x=脚/2-头
即兔子的个数为脚/2-头
*/
public class 鸡兔同笼 {
public static void main(String[] args) {
int h = 35;
int f = 94;

int r= f/2-h;
int c=h-r;
System.out.println("笼中有鸡" + c + "只,兔" + r + "只");
}
}
第2个回答  2020-03-08
以“今有雉兔同笼,上有三十五头,下有九十四足,问雉兔各几何?”为例
12345678910public class test { public static void main(String[] args) { int x,y; //x:鸡 y:兔 for(x=0;x<=35;x++) { //遍历鸡的只数 y=35-x; //兔的只数等于35 - 鸡 if(2*x+4*y==94) //如果鸡和兔的脚总数是94 System.out.println("鸡"+x+"只,兔"+y+"只"); } }}
第3个回答  2020-12-08

本节课教大家如何运用scratch编程解决鸡兔同笼的数学问题—晨煊少儿编程

第4个回答  2013-09-26
一楼的正解