zoukankan      html  css  js  c++  java
  • Java实现三人年龄

    2 三人年龄

    三个神秘蒙面人来访F博士。
    博士询问他们年龄时,他们说:我们中年龄最小的不超过19岁。我们3人年龄总和为70岁。且我们三人年龄的乘积是所有可能情况中最大的。
    请帮助F博士计算他们的年龄,从小到大排列,用逗号分开。

    参考答案:
    19,25,26

    public class Main {
    
        public void printResult() {
            int[] A = new int[3];
            int max = 0;
            for(int a = 1;a < 100;a++) {
                for(int b = 1;b < 100;b++) {
                    for(int c = 1;c < 100;c++) {
                        int min = a;
                        if(min > b)
                            min = b;
                        if(min > c)
                            min = c;
                        if(min > 19)
                            continue;
                        if(a + b + c == 70) {
                            if(a*b*c > max) {
                                A[0] = a;
                                A[1] = b;
                                A[2] = c;
                                max = a*b*c;
                            }
                        }
                            
                    }
                }
            }
            System.out.println(A[0]+", "+A[1]+", "+A[2]+", "+max);
        }
        
        public static void main(String[] args) {
            Main test = new Main();
            test.printResult();
        }
        
    }
    
  • 相关阅读:
    oc结构
    iOS分类
    iOS协议
    缓存无底洞现象
    数据库备份,恢复
    PHP邮件发送库:Swiftmailer
    PHP分页组件:Paginator
    PHP验证码类
    PHP日期和时间处理组件-Carbon
    composer的一些操作
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076751.html
Copyright © 2011-2022 走看看