import java.util.*;
public class Anagrams问题 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
while(in.hasNext()){
String a=in.next().toLowerCase();
//转为小写
String b=in.next().toLowerCase();
char[]arr1=a.toCharArray();
//转为字符数组
char[]arr2=b.toCharArray();
Arrays.sort(arr1);
//排序
Arrays.sort(arr2);
int flag=1;
//标记
if(arr1.length!=arr2.length)
//比较长度是否相等
System.out.println("N");
else{
for(int i=0;i<arr1.length;i++){
if(arr1[i]!=arr2[i])
flag=0;
}
}
if(flag==1)
System.out.println("Y");
else
System.out.println("N");
}
}
}
原文地址:http://blog.csdn.net/a736933735/article/details/43865785