I had written a program will add two array and put it into third array with removing duplicate
i am getting out put with some extra zero... need help on this class readArray { public static void main (String arg[]) { int[] arry1 = {0,1,5,9,34,45,54,23,34}; int[] arry2 = {2,5,90,76,54}; int[] resArry = new int[arry1.length+arry2.length]; addToArray(resArry,arry1,0); addToArray(resArry,arry2,arry1.length); sortArry(resArry); //deleteDup(resArry); for(int i =0; i<resArry.length; i++){ System.out.println(resArry[i]); } } /* Merge 2 array*/ public static void addToArray(int[] resArry, int[] arry,int x){ int dup = 0; for (int i = 0; i < arry.length; i++) { for(int j = 0; j < resArry.length;j++) { if(resArry[j] == arry[i]) { dup = dup+1; } else { dup =dup+0; } } if (dup <= 0) { resArry[x] = arry[i]; x++; } dup = 0; } } /* Sort array*/ public static void sortArry(int[] x) { int n = x.length; for (int pass=1; pass < n; pass++) { for (int i=0; i < n-pass; i++) { if (x[i] > x[i+1]) { int temp = x[i]; x[i] = x[i+1]; x[i+1] = temp; } } } } /* Delete duplicate value in the array*/ /*public static void deleteDup(int arr[]){ int newArray[] = new int[arr.length]; int temp =0; int count= 0; int len = 0; for(int i =0; i<arr.length; i++){ temp =arr[i]; int val =i+1; if(val < arr.length){ if(temp ==arr[val]) continue; len = len+1; } newArray[count++] =temp; } for(int i =0; i<=len; i++){ System.out.println(newArray[i]); } }*/ } -- You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en To unsubscribe, reply using "remove me" as the subject.