<无详细内容>
- public class AlgorithmTest {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int money = 100;
- int count = 100;
-
- System.out.println(money + "钱买" + count + "鸡的求解方案 :");
-
- baiQianMaiBaiJi(money,count);
- }
- public static void baiQianMaiBaiJi(int money, int count) {
-
- int cock = 0;
- int hen = 0;
- int chick = 0;
-
- for (cock = 0; cock < count; cock++) {
- for (hen = 0; hen < count; hen++) {
- chick = count - cock - hen;
- if ((chick % 3 == 0) &&(cock * 5 + hen * 3 + chick/3) == 100 ) {
- System.out.println("买了公鸡:"+cock+"只,母鸡"+hen+"只,小鸡"+chick+"只");
- }
- }
- }
-
- }
- }
复制代码 |