---
title: "经典数学解析-鸡兔同笼"
author: "DepthJava"
date: "2010-07-02T15:43:45Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-07-02T15:43:45Z"
id: 704473
url: "https://depthjava.iteye.com/blog/704473"
---

大约在一千五百年前，大数学家孙子在《孙子算经》中记载了这样的一道题：“今有雏兔同笼，上有三十五头，下有九十四足，问雏兔各几何？

```
	private static final int head = 35; // 头有35个
	private static final int foot = 94; // 脚有94个
	private static final int chicken = 2; // 鸡有2只脚
	private static final int rabbit = 4;  //兔有4只脚
	
	public static void main(String[] args) {
		int count_ck,count_rb;
		for(count_ck=0;count_ck<foot/2;count_ck++){
			for(count_rb=0;count_rb<foot/4;count_rb++){
				if((count_rb+count_ck==head) && (count_rb*4+count_ck*2==94)){
					System.out.println("鸡："+count_ck);
					System.out.println("兔："+count_rb);
				}
			}
		}

	}
```

 

结果：

 

鸡：23  
兔：12