im asked to write a program that removes duplicate letters from a string **note: uppercase and lowercase letters are considered duplicates. I wrote the code and it's working for all inputs without spacebars, when an string is given with spaces, it show errors. i have to use loops and arrays only, no extra functions or hashs, this is my code that ALMOST works:
case 2:
System.out.println("Give the string input");
String original=reader.next();
char[] charts=original.toCharArray();
int length=charts.length;
for (int i=0; i<length; i++){
for (int j=i+1; j<length; j++){
if(charts[i]==charts[j]||charts[i]+32==charts[j] ||charts[i]-32==charts[j]){
int temp=j; //duplicate element index
for (int k=temp; k<length-1; k++){ //delete shifting elements to left.
charts[k]=charts[k+1];
}//inner inner for
j--;
length--; // reduce char array length because we removed a character
}//if
}//inner for
}//for
String CleanString= new String(charts); //new string without repeated chars
CleanString=CleanString.substring(0,length); //set its length
System.out.println("New str = "+CleanString);
break;