public class StringEx {
public static void main(String[] args){
String s1 ="abcc";
String s2 = "cbaa";
getCommon(s1,s2);
}
private static void getCommon(String s1, String s2) {
char[] c1 = s1.toCharArray();
char[] c2 = s2.toCharArray();
char[] commonAry = new char[10];
for(int i=0;i < (c1.length)-1;i++){
for(int j=0;j<(c2.length)-1;j++){
if(c1[i]==c2[j]){
int k=0;
commonAry[k]=c1[i];
k++;
}
}
}
System.out.println(commonAry);
}
}
the above program is giving an output like "c n some square boxer after that".. what is wrong in above code.