您的位置:首页 > 编程语言 > Java开发

code hunt 题解八(java版)

2015-06-26 10:47 561 查看
07.01
<pre name="code" class="java">public class Program {
public static String Puzzle(String one, String two, String three) {
return two+three+one+one+three+two;
}
}




07.02

public class Program {
public static String Puzzle(String s) {
return s.substring(0,s.length()/2);
}
}
07.03

public class Program {
public static String Puzzle(String a, String b, String c) {
return a.replace(b,c);
}
}07.04
public class Program {
public static String Puzzle(String s) {
return new StringBuilder(s).reverse().toString();
}
}

07.05
public class Program {
public static String Puzzle(String a, String b) {
char [] cha = a.toCharArray(), chb = b.toCharArray();
int len = a.length();
for (int i = 0; i < len; i+=2) {
cha[i] = chb[i];
}
return new String(cha);
}
}

07.06
public class Program {
public static String Puzzle(String s) {
return s.replace(" ", "");
}
}

07.07
public class Program {
public static String Puzzle(String s) {
return s.replaceAll("a|e|i|o|u","");
}
}

07.08
public class Program {
public static Boolean Puzzle(String input, String a, String b, String c) {
int ia = input.indexOf(a);
if (ia == 0) {
int ib = input.indexOf(b);
if (ib >= 0 && ib <= input.length() - c.length()) {
if (input.lastIndexOf(c) == input.length() - c.length()) {
return true;
}
}
}
return false;
}
}

07.09
public class Program {
public static String Puzzle(int i, String s) {

return i == 1 ? s: s+" "+Puzzle(i-1, s);
}
}

07.10   没有三星
public class Program {
public static String Puzzle(int t) {
String str = "a b c d e f g h i j k l m n o p q r s t u v w x y z ";
String res = "";
for (int i = 1; i < t; i++) {
res += str;
}
res += str.substring(0, 52 - 2*t);
res += "z";
return res;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  code hunt java