java - List Intersection -


given 2 lists of integers no duplicates. intersection of 2 lists list of integers in both lists, when run program ouput wrong, can 1 me figure out did messed up

public class  list_intersection {     public int [] intersection (int [] tab1, int []tab2) {         int [] result = new int [7];         int k = 0;         (int i=0; i< tab1.length; i++) {             (int j=0; j<tab2.length; j++)                 if(tab1[i]==tab2[j])                     result[k++]=tab1[i];         }         return result;     }      public static void main(string[] args){         intersection_union a= new intersection_union ();         int [] tab1= { 4, 7, 12, 6, 17, 5 , 13};         int [] tab2= { 7, 19, 4, 11, 13, 2, 15};         int [] res = new int [7];         res=a.intersection(tab1, tab2);         system.out.println(" l'intersection est : " + res);     } } 

i think problem can't system.out.println array.

you can use loop print out content of array.

system.out.print(" l'intersection est : "); (int i=0; i<7; i++) {   system.out.print(res[j]); } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -