62,628
社区成员
发帖
与我相关
我的任务
分享
String[] test= new String[100];
for(int i = 0 ; i<50;i++){
test[i] = ""+i;
}
test[9] = "<&>";
test[19] = "<&>";
test[29] = "<&>";
test[39] = "<&>";
test[49] = "<&>";
String[] test2 = new String[100];
int j =0;
for(int i=0;i<50;i++){
if(test[i] !="<&>"){
test2[j]=test[i];
j++;
}else {
test2[j]=test[i];
j++;
test2[j] = "<&>";
j++;
}
}
这题看似很简单,但题目要求不能用字符串或数组的相关方法(如equals),实际上比较难。
,但题目描述中提到不能用字符串的方法,如equals
,但题目描述中提到不能用字符串的方法,如equals
public static void main(String[] args) {
String[] text = {"<$>","1","<$>","<$>","2","<$>","","","","","",""};
int flag=0;
for(int i=0;i<=5;i++){
text[i+6]=text[i];
text[i]="";
}
for(int i=6;i<text.length;i++){
if("<$>".equals(text[i])){
text[flag++]="<$>";
text[flag++]="<$>";
}else{
text[flag++]=text[i];
}
text[i]="";
}
for(String string:text){
System.out.println(string);
}
}