for(i=0;i<m1.length();i++)
for(j=0;j<m2.length();j++)
if(m1.charAt(i)==m2.charAt(j)){
intersection=intersection+m1.charAt(i);
m2.charAt(j)=' ';
}
System.out.println(intersection);
} while(devam==false);
}
}
that’s my code. and we are not allowed to use a method or an array, we are just beginners.my code gives an error at the point of m2.charAt(j)=' ';. i wrote that line because, when we find an intersection, we shouldn’t check that element again.can you please help?
You cannot modify the content of a String with
Do this instead
Note that replace() will replace the first character in the string equal to the first parameter. I assume that, since the string represent a set, will not be repeated characters. If there are and you want to replace all of them, just use replaceAll() instead.