import java.util.Arrays;
public class test{
/*
isEqual()这个函数是判断两个字符串中是否有相等的字符
*/
public static boolean isEqual(String a,String b){
char[] char1 = a.toCharArray();
char[] char2 = b.toCharArray();
for(int i = 0;i < char1.length;i++){
for(int j = 0;j < char2.length;j++){
if(char1[i] == char2[j]){
return true;
}
}
}
return false;
}
/*
版主在这里设置了一个临时boolean型判断变量
这个变量是用来判断设置具有相同子字符的字符串为空字符串的依据
我不用很复杂的方法,用你能看得懂的方法实现,虽然效率不高
但若要效率高的,同样也能写出,不过要调用好多类
如果我这样做了,你肯定会看不懂,你自己也说了HashMap没学过
*/
public static void main(String[] args){
String[] A = {"1q","2w","3e","3r","5t","4y","7u","8i","8o","1p"};
boolean TempJudge = false;
for(int i = 0;i < A.length;i++){
TempJudge = false;
for(int j = i + 1;j < A.length;j++){
if(isEqual(A[i],A[j]) == true){
TempJudge = true;
A[j] = "";
}
}
if(TempJudge){
A[i] = "";
}
}
for(int i = 0;i < A.length;i++){
if(A[i] != ""){
System.out.print(A[i] + " ");
}
}
}
}
运行截图:
|