public class Derived{
public String unique_string (String s) {
// write code here
String aa = new String();
char[] chars = s.toCharArray();
int j ;
Boolean flag;
for(int i = 0; i < chars.length; i++){
flag = true;
for(j = 0;j < aa.length(); j++){
if(chars[i] == aa.charAt(j)){
flag = false;
break;
}
}
if(flag){
aa += chars[i];
}
}
return aa;
}
public static void main(String[] args) {
Derived derived = new Derived();
Scanner input = new Scanner(System.in);
System.out.print("请输入需要去重的字符:");
String str = input.next();
String qwyqcbhaqijv = derived.unique_string(str);
System.err.println(qwyqcbhaqijv);
}
}
这道题的考察点在于需要处理有相邻重复字符的处理方式和重复字符在字符串末尾的字符操作,准确判定就没有问题啦!!