public static void main(String[] args)
{
char[] x = {'b', 'l', 'a', 'h', 'h', ' '};
char[] y = {'g', 'o', 'g', 'o'};
System.out.println(removeDuplicate(x, y));
System.out.println(noDuplicate(y, x));
public static char[] removeDuplicate(char[] first, char[] second)
{
//used my append method (didn't enclose) to append the two words together
char[] total1 = append(first, second);
//stores character that have been encountered
char[] norepeat = new char[total1.length];
int index = 0;
//store result
char[] solution = new char[total1.length];
boolean found = false;
//for loop keeps running until blahh gogo is over
for(int i = 0; i < total1.length; i++)
{
for(int m = 0; m <norepeat.length; m++)
{
if(total1[i] == norepeat[m])
{
found = true;
break;
}
}
if (!found)
{
norepeat[index] = total1[i];
index++;
solution[index] = total1[i];
index++;
}
}
return solution;
}
}
Current Output:
blah
go
I Want the Output to be:
blah go
goblah (space at the end)
The problem with my code is that it stops running after encountering the first repeat, so it doesn't even run the whole words at all. I believe that it has something to do with my nested for loop, but I am not sure. I tried writing it out on paper, but it doesn't seem to help any.
Any help would be appreciated! Thank you!