code hunt 题解七(java版)

06.01  。。。

public class Program {
    public static Boolean Puzzle(String s) {
        return false;
    }
}

06.02  这一个没有三星,我试了很多种姿势都没有。。。有人三星的话求告知

public class Program {
    public static String Puzzle(String s) {
        String res = "";
        String s1 = s.toLowerCase();
        String s2 = s.toUpperCase();
        for (int i = 0; i < s.length(); i++) {
            if (i%2 == 0) {
                res+= s2.charAt(i);
            } else {
                res+= s1.charAt(i);
            }
        }
        return res;
    }
}

06.03 本题同上

public class Program {
    public static String Puzzle(String s) {
        int i, gap = 'A'-'a';
        char[] ch = s.toCharArray();
        for (i = ch.length-1; i >= 0; i--) {
            if (Character.isLetter(ch[i])) {
                ch[i] = (char)(ch[i]+gap);
                i--;
                while (i >= 0 && Character.isLetter(ch[i])) {
                    i--;  
                }
            }
        }
        return new String(ch);
    }
}

06.04

public class Program {
    public static char Puzzle(String s, int x) {
        return s.charAt(x);
    }
}

06.05

public class Program {
    public static String Puzzle(String one, String two) {
        return two+one;
    }
}

06.06

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

06.07  多试几次就看出来了

public class Program {
    public static String Puzzle(String s) {
        int len = (s.length()-1)/2;
        return s.substring(s.length()-len).toUpperCase()+s.substring(s.length() - len - 1);
    }
}

06.08

public class Program {
    public static int Puzzle(String a, String b) {
        int lenA = a.length(), lenB = b.length();
        return lenA>lenB?lenA:lenB;
    }
}

06.09  请忽略变量的命名。。。

public class Program {
    public static String Puzzle(String a, String b) {
        int lena = a.length(), lenb = b.length();
        if (lena > lenb) {
            return a;
        } else if (lena < lenb) {
            return b;
        } else {
            return a+b;
        }
    }
}

06.10

public class Program {
    public static int Puzzle(String s) {
        return (s.length()/3);
    }
}

06.11  

public class Program {
    public static String Puzzle(int i, int j, String s) {
        return s.substring(i, s.length() - 1) + s.substring(j, s.length() - 1);
    }
}

06.12

public class Program {
    public static String Puzzle(String s) {
        return s+(new StringBuilder(s).reverse().toString());
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值