I'm trying to delete duplicate characters from a string. For example if I enter the string abaqueru it should give me bqer with duplicate characters a and u deleted. However, instead the result is an unnecessary loop. Here is the code:
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);
}
}
System.out.println(s);
}
}