code hunt 题解八(java版)
2015-06-26 10:47
561 查看
07.01
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;
}
}
<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;
}
}
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树
- [原创]java局域网聊天系统