一个笼子中有50只小鸡和小兔子,160只脚。
求小鸡和小兔子各有多少只?
方法一
public class TestOne{
public static void main(String[] args){
//定义变量x存储小鸡的个数
for(int x=1;x<50;x++){
if(2*x + 4*(50-x)==160){
System.out.println("有小鸡" + x + "只");
System.out.println("有小兔" + (50-x) +"只");
}
}
}
}
代码运行结果