- public class Test {
- public static void main(String[] args) {
- int arr[] = new int[1000];
- int a, b, c, d, e, f, k, i;
- int x, y, z, o, p, q, r, s, t;
- for (i = 123, k = 0; i <= 987; i++) {
- a = i % 10;
- b = i / 10 % 10;
- c = i / 100;
- if (a != b && b != c && a != c && b != 0 && a != 0) { //求得一個三位數的各個位數都不相同,並存到數組中
- arr[k] = i;
- k++;
- }
- }
- int sum = 1;
- for (int m = 1; m <= 9; m++) //求得9!
- sum = sum * m;
- //System.out.println(sum);
- for (d = 0; d <= arr.length - 1 && arr[d] != 0; d++) {
- o = arr[d] % 10;
- p = arr[d] / 10 % 10;
- q = arr[d] / 100;
- for (e = 0; e <= arr.length - 1 && arr[e] != 0; e++) {
- r = arr[e] % 10;
- s = arr[e] / 10 % 10;
- t = arr[e] / 100;
- if(arr[d]==arr[e]) continue; //爲減少循環的次數,當第一個數與第二個數相同時,繼續下一層循環
- for (f = 0; f <= arr.length - 1 && arr[f] != 0; f++) {
- x = arr[f] % 10;
- y = arr[f] / 10 % 10;
- z = arr[f] / 100;
- if(arr[f]==arr[e]||arr[f]==arr[d]) continue;//同上
- if (((arr[d] + arr[e]) == arr[f]) && (arr[e] == 2 * arr[d])
- && (o * p * q * s * r * t * x * y * z == sum))
- System.out.println(arr[d] + " " + arr[e] + " " + arr[f]);
- }
- }
- }
- }
- }
運行結果:192 384 576
219 438 657
273 546 819
327 654 981