I want to get the common values of list1 and compare it to list2. I got an output of 11121 instead of 121. How can I resolve this?
Here's my code:
public class TwoLists {
static void arrs() {
int[] list1 = {1, 6, 2, 1, 4, 1, 2, 1, 8};
int[] list2 = {1, 2, 1};
for(int i = 0; i < list1.length-1; i++)
{
for(int o = i+3; o < list1.length; o++)
{
for(int out1 = list1[i]; out1 == list1[o]; out1++)
{
System.out.print(out1);
}
}
}
}
public static void main(String[] args)
{
arrs();
}
}