package com.cucu;/**
 * @author CuCuChen
 * @version $Id$
 * @since 2004-5-6
 */
public class math {
    public void helpLvlisong22() {
        int[] numbers = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int countNum = 1;
        for (int a = 0; a < numbers.length; a++) {
            for (int b = 0; b < numbers.length; b++) {
                for (int c = 0; c < numbers.length; c++) {
                    for (int d = 0; d < numbers.length; d++) {                        if (a!=b&&b!=c&&a!=c&&a!=d&&b!=d&&c!=d) {
                            if (a + b + c + d == 28) {
                   System.out.println("\nThis is the " + countNum + " time\n");
                   System.out.println("\nThe a is" + a + "\n");
                   System.out.println("\nThe b is" + b + "\n");
                   System.out.println("\nThe c is" + c + "\n");
                   System.out.println("\nThe d is" + d + "\n");
                                countNum++;
                            }
                        }
                    }
                }
            }
        }    }
}
//运行结果5,6,8,9或者:4,7,8,9(重复不计入内)

解决方案 »

  1.   

    又把方法改了一下,现在完全可以了:)))
    package com.cucu;/**
     * @author CuCuChen
     * @version $Id$
     * @since 2004-5-6
     */
    public class math {
        public void helpLvlisong22() {
            int[] numbers = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            int countNum = 1;
            for (int a = 0; a < numbers.length; a++) {
                for (int b = 0; b < numbers.length; b++) {
                    for (int c = 0; c < numbers.length; c++) {
                        for (int d = 0; d < numbers.length; d++) {                        if (a!=b&&b!=c&&a!=c&&a!=d&&b!=d&&c!=d) {
                                if (a + b + c + d == 28&&a<b&&b<c&&c<d) {
                                    System.out.println("\nThis is the " + countNum + " time\n");
                                    System.out.println("\nThe a is" + a + "\n");
                                    System.out.println("\nThe b is" + b + "\n");
                                    System.out.println("\nThe c is" + c + "\n");
                                    System.out.println("\nThe d is" + d + "\n");
                                    countNum++;
                                }
                            }
                        }
                    }
                }
            }    }
    }
      

  2.   

    晕死了,那还不是一样吗?将数组定义为float不就OK了吗?兄弟,要学会举一反三啊~:)))
      

  3.   

    //对不起刚才的程序有bug,现在更正如下,如果你用float即把数组改为float就OK了!如下:
    package com.cucu;/**
     * @author CuCuChen
     * @version $Id$
     * @since 2004-5-6
     */
    public class math {
        public void helpLvlisong22() {
            int[] numbersa = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            int[] numbersb = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            int[] numbersc = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            int[] numbersd = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            int countNum = 1;
            for (int a = 0; a < numbersa.length; a++) {
                for (int b = 0; b < numbersb.length; b++) {
                    for (int c = 0; c < numbersc.length; c++) {
                        for (int d = 0; d < numbersd.length; d++) {                if (numbersa[a]!=numbersb[b]&&numbersb[b]!=numbersc[c]
                           &&numbersa[a]!=numbersc[c]&&numbersa[a]!=numbersd[d]
                           &&numbersb[b]!=numbersd[d]&&numbersc[c]!=numbersd[d]) {
                        if (numbersa[a] +numbersb[b]+ numbersc[c] + numbersd[d] == 28
                                        &&numbersa[a]<numbersb[b]
                                        &&numbersb[b]<numbersc[c]
                                        &&numbersc[c]<numbersd[d]) {
                        System.out.println("\nThis is the " + countNum + " time\n");
                        System.out.println("\nThe a is" + numbersa[a] + "\n");
                        System.out.println("\nThe b is" + numbersb[b] + "\n");
                        System.out.println("\nThe c is" + numbersc[c] + "\n");
                        System.out.println("\nThe d is" + numbersd[d] + "\n");
                                    countNum++;
                                }
                            }
                        }
                    }
                }
            }    }
    }