牛课网学习--编程练习

//确定字符互异public class Different { public boolean checkDifferent(String iniString) { // write code here /*char[] c = iniString.toCharArray(); boolean b = true; for (int i = 0; i < c.length; i++) { for (int j = 1; j < c.length; j++) { if(c[i]==c[j]) { b = false; } else {b = true;}}}return b;*/ return !iniString.matches(".*(.)(.*\\1).*"); }}//空格替换public class Replacement { public String replaceSpace(String iniString, int length) { // write code here String a = iniString.replaceAll("\\s", "%20"); return a; } }//确定两串乱序同构public class Same { public boolean checkSam(String stringA, String stringB) { // write code here char[] a = stringA.toCharArray(); char[] b = stringB.toCharArray(); Arrays.sort(a); Arrays.sort(b); boolean b1 = true; for (int i = 0; i < b.length; i++) { if(a[i]!=b[i]) { b1=false; }} return b1; } public static void main(String[] args) { System.out.println(new Same().checkSam("Here you are", "are you Here"));}}

你可能感兴趣的:(Java基础练习,string)