code hunt 题解八(java版)

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;
    }
}





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值