在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

买钱买百鸡

2016-7-29 15:47| 发布者: zhangjf| 查看: 756| 评论: 0

摘要: 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 + 钱买 + ...
<无详细内容>
  1. public class AlgorithmTest {
  2. /**
  3. * @param args
  4. */
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7. int money = 100;
  8. int count = 100;
  9. System.out.println(money + "钱买" + count + "鸡的求解方案 :");
  10. baiQianMaiBaiJi(money,count);
  11. }
  12. public static void baiQianMaiBaiJi(int money, int count) {
  13. int cock = 0;
  14. int hen = 0;
  15. int chick = 0;
  16. for (cock = 0; cock < count; cock++) {
  17. for (hen = 0; hen < count; hen++) {
  18. chick = count - cock - hen;
  19. if ((chick % 3 == 0) &&(cock * 5 + hen * 3 + chick/3) == 100 ) {
  20. System.out.println("买了公鸡:"+cock+"只,母鸡"+hen+"只,小鸡"+chick+"只");
  21. }
  22. }
  23. }
  24. }
  25. }
复制代码

最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-7-6 20:35

Copyright 2015-2025 djqfx

返回顶部