计算()()()+()()()=()()()


题目:()()()+()()()=()()(),请将1~9这9个数字填入9个括号中并使等式两边成立,每个数字只能使用一次;


代码:

public class Test {

    public static void main(String[] args) {
        test002();
    }

    /**
     * 测试二
     * 问题描述:()()()+()()()=()()()
     * 请将1~9这9个阿拉伯数字分别填入9个括号中使等式两边成立,每个数字只能使用一次
     */
    private static void test002(){
        int a,b,c,d,e,f,g,h,i;
        for ( int m=100;m<1000;m++ ){
            for ( int n=100;n<1000;n++ ){
                for ( int o=100;o<1000;o++ ){
                    if ( (m+n)==o ){
                        a = m/100;
                        b = (m%100)/10;
                        c = m-100*a-10*b;
                        d = n/100;
                        e = (n%100)/10;
                        f = n-100*d-10*e;
                        g = o/100;
                        h = (o%100)/10;
                        i = o-100*g-10*h;
                        int[] arr = {a,b,c,d,e,f,g,h,i};
                        boolean bol = checkArrRepeat(arr);
                        if ( !bol ){
                            System.out.println(m+","+n+","+o);
                        }
                    }
                }
            }
        }

    }

    /**
     * 判断数组是否重复
     *
     * @param arr 入参
     * @return 有重复返回true,无重复返回false
     */
    private static boolean checkArrRepeat( int[] arr ){
        for ( int i=0;i<arr.length;i++ ){
            for ( int j=i+1;j<arr.length;j++ ){
                if ( arr[i]==arr[j] ){
                    return true;
                }
            }
        }
        return false;
    }

}


答案:

103,469,572
103,479,582
103,579,682
103,649,752
103,749,852
103,759,862
104,579,683
104,759,863
105,269,374
105,279,384
105,387,492
105,629,734
... ...
... ...



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jalen备忘录

谢谢~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值