问题描述:
哈哈,不用描述了吧
思路分析:
设鸡有x只,兔有y只,可列方程:x+y=head;2x+4y=foot;
联立两式:x=(4head-foot)/2; y=(foot-2head)/2;
代码示范:
package 鸡兔同笼;import java.util.Scanner;public class JandT {public int chook(int head,int foot) {int chook = (4*head-foot)/2;return chook;}public static void main(String[] args) {// TODO Auto-generated method stubJandT JT = new JandT();Scanner sc = new Scanner(System.in);System.out.println("请输入head :");int head = sc.nextInt();System.out.println("请输入foot :");int foot = sc.nextInt();int x = JT.chook(head, foot);int y = head-x;System.out.println("笼子里有"+x+"只鸡,"+y+"只兔;");}}
测试结果: