import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
* 假设字符串类似这样的aba和aab就相等,现在随便给你二组字符串,请编程比较他们看是否相等
* */
public class EqualDemo {
public static void main(String[] args) {
//先读取到一串字符
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
StringTokenizer st = new StringTokenizer(s," ");
/*if(st.hasMoreTokens()){
System.out.println(st.nextToken());
}*/
String s1=st.nextToken();
String s2 = st.nextToken();
System.out.println(s1);
System.out.println(s2);
StringBuffer st2 = new StringBuffer(s2);
if(s1.length()!=s2.length()){
System.out.println("no equals");
return;
}
for(int i = 0;i
StringBuffer t = new StringBuffer();
t.append(s1.charAt(i));
int index = 0;
if((index=st2.indexOf(t.toString()))!=-1){
st2.deleteCharAt(index);
}else{
System.out.println("not equals");
return;
}
}
if(st2.length()==0){
System.out.println("equals");
}
}
}
原文:http://www.cnblogs.com/sylovezp/p/4126393.html