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();
        }
        
    }
    
  • 相关阅读:
    git常用命令
    代码实现-栈、队列、双端队列
    websocket实现简单的单聊
    websocket实现简单的群聊
    成员
    反射
    类与类之间的关系
    常用模块-02
    模块
    微信小程序表单多页面步骤提交
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12947351.html
Copyright © 2011-2022 走看看