我正在尝试从字符串中删除重复的字符.例如,如果我输入字符串,abaqueru它应该给我bqer重复的字符a并u删除.但是,结果是不必要的循环.这是代码:
public class question {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String s = "abaqueru";
calculate(s);
// TODO code application logic here
}
public static void calculate(String s){
String result;
for(int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
char temp;
temp=c;
for(int j = 1; j < s.length(); j++)
{
char x = s.charAt(j);
if(temp==x){
s=s.replaceAll(""+temp,"");
calculate(s);
} …Run Code Online (Sandbox Code Playgroud)