题目描述
思路分析
方案一:不定顺序:要除以6.
方案二:人为规定:a <= b <= c
代码实现
方案一
package com.atguigu.TEST;class Main{public static void main(String[] args) {int sum=0;for (int i = 1; i <=1999; i++) {for (int j = 1; j <=1999; j++) {for (int k = 1; k <=1999; k++) {if((i+j+k==2019)&&check(i)&&check(j)&&check(k)&&(i!=j)&&(j!=k)&&(i!=k)){sum++;}}}}System.out.println(sum/6);}public static boolean check(int i){String a=i+"";if (a.indexOf('2')!=-1){return false;}if (a.indexOf('4')!=-1){return false;}return true;}}
方案二
package com.atguigu.TEST;class Main{public static void main(String[] args) {int sum=0;for (int i = 1; i <=1999; i++) {for (int j = i+1; j <=1999; j++) {for (int k = j+1; k <=1999; k++) {if((i+j+k==2019)&&check(i)&&check(j)&&check(k)&&(i!=j)&&(j!=k)){sum++;}}}}System.out.println(sum);}public static boolean check(int i){String a=i+"";if (a.indexOf('2')!=-1){return false;}if (a.indexOf('4')!=-1){return false;}return true;}}
答案
40785