package cn.coder.rabbitmq.test;
import java.util.HashMap;
import java.util.Map;
public class Test {
static int rabbit;
static int bow;
/**
*
* 鸡和兔子若干只,头有35个,脚有94个,求兔子和鸭个多少只
*
*/
public static void main(String[] args) {
getNum(35,94);
}
/**
*
* @param head 头
* @param foot 脚
* @return map
*/
public static Map<String,Integer> getNum(int head,int foot){
int rab=0; //兔子
int bow; //鸡
for (bow = 0; bow < head; bow++) {
rab=head-bow; //通过与兔子同相同数为head(一共的只数)
if((rab*4)+(bow*2)==94) {
/* 如果兔子的的只数*4只脚+鸡的只数*2只脚等于94的时,就得到了兔子和鸡的只数。*/
System.out.println("兔子:"+rab+"鸡:"+bow);
}
}
Map<String,Integer> map=new HashMap<String, Integer>();
map.put("小鸡", bow);
map.put("兔子", rab);
return map;
}
}