char j='\u0000';
while (n<characters.length-1){>
for (k=i+1; k < characters.length-1; k++){
if (characters[k]==' '){
characters[k]=j;
}
You are replacing a space with a null which indicates the end of the string. All characters beyond the null will now be ignored. You are supposed to remove duplicate spaces, and add null characters at the end of the array where the previous characters have been moved from.
You should move the remaining characters in the array up the array, overwriting the repeated spaces. You then add nulls at the end of the aray according to the number of spaces overwritten. Try writing it down on paper first to see exactly what each step should do, before converting to code.