楼主:
psplay (乱世中一个小小书僮)
2014-10-02 11:29:27※ 引述《NoMoneys (没有钱)》之铭言:
: 小弟涉入程式尚浅
: 想了许久还是解不出来
: ex:135246→123456
: acebd→abcde
: wrdol→world
: 像是这样输出结果
: 希望高手帮忙解答感谢
: 不好意思 我想请问的是程式码该如何撰写才能达到这样的答案
: 左边是输入右边是输出
public void testCase01(){
String[] test = {"wrdol", "acebd", "135246"};
for(int i=0; i<test.length; i++){
String s1 = "";
String s2 = "";
if(test[i].length()%2==0){
s1 = test[i].substring(0, test[i].length()/2);
s2 = test[i].substring(test[i].length()/2, test[i].length());
}else{
s1 = test[i].substring(0, test[i].length()/2+1);
s2 = test[i].substring(test[i].length()/2+1, test[i].length());
}
System.out.print("result: ");
for(int j=0;j<s1.length();j++){
System.out.print(s1.substring(j, j+1));
if(s2.length()>j){
System.out.print(s2.substring(j, j+1));
}
}
System.out.println();
}
}
来 楼下请开嘘
这应该是连高中生程度都能写出来的程式就是了.....
喵的我竟然再帮人家写作业= =