编码需求
判定两个指定的字符串是否异构同质;异构同质的定义为:一个字符串的字符重新排列后,能变成另一个字符串。
编码实现
import java.util.Arrays;
import java.util.Scanner;
public class SameCharStr {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
String str1 = scanner.next();
String str2 = scanner.next();
char[] char1 = str1.toCharArray();
char[] char2 = str2.toCharArray();
Arrays.sort(char1);
Arrays.sort(char2);
boolean result = true;
for (int i = 0; i < char1.length; i++) {
if (char1[i] != char2[i]) {
result = false;
break;
}
}
System.out.println(result);
}
}
}
网友评论