百鸡百钱

public class JiDan {

    public static void main(String[] args) {
       

        // 公鸡 a = 2;母鸡 b = 1; 小鸡 c = 0.5;

        // 用100文钱,买100只鸡
        int a , b ;
        
        for (a = 0; a < 100; a++) {
            for (b = 0; b <= 100; b++) {
                int c = 100 - a - b;
                if (c % 2 == 0) {
                    if ((2 * a + 1 * b + 0.5 * c) == 100){
                        System.out.print("a =" + a + " ");
                        System.out.print("b =" + b + " ");
                        System.out.print("c =" + c + " ");

                        System.out.println(" ");
                    }

                        
                }

            }

        }
    }
}

 

posted @ 2015-12-07 08:39  琦仔  阅读(131)  评论(0编辑  收藏  举报