/**
     * 陣列差集運算。( 回傳值 = A - B )
     */
    public String[] except(String[] A, String[] B) {
        String[] C = new String[A.length - B.length];
        int count=0;
        for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < B.length; j++) {
                if (A[i].equals(B[j])) {
                    A[i] = "";
                }
            }
            if (!A[i].equals("")) {
                C[count]=A[i];
                count++;
            }
        }   
        return C;
    }
}

/*
執行程式碼 : 
 
String a = {"1","2","3","4","5"};
String b = {"1","3","5"};
 
System.out.pringln(except(a,b));
 
執行結果 : 
 
[2,4]
 
 
*/ 
arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(2) 人氣()