请教大家,一道面试题,限制诸多,不知怎么实现比较合适?

qq_29448025 2017-06-18 06:54:35
...全文
767 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
fei550223122 2017-06-29
  • 打赏
  • 举报
回复
字符数组定义的长度为100,开始有50个元素,最后最多变为100个 应该是这样变的 char[] ch = new char[]{'a','$','c'}; char[] ch = new char[]{'a','$','$','c'}; 添加元素
java_no1best 2017-06-25
  • 打赏
  • 举报
回复
可以定义为char 字符型数组,这样的话直接取的就是字符而不是地址可以直接用==
u010004204 2017-06-25
  • 打赏
  • 举报
回复
上面说的好像都不太对吧。。题目说的是字符数组啊,他们都定义字符串数组干嘛?
-天宇 2017-06-23
  • 打赏
  • 举报
回复
考验基纯本功
残风炫舞 2017-06-21
  • 打赏
  • 举报
回复

                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++;
			}
			
		}
qq_29448025 2017-06-21
  • 打赏
  • 举报
回复
引用 1 楼 u012613902 的回复:
看来大家都懒得回复,java基础啊。还是要注重基础的培养
这题看似很简单,但题目要求不能用字符串或数组的相关方法(如equals),实际上比较难。
qq_29448025 2017-06-21
  • 打赏
  • 举报
回复
引用 2 楼 CSDNSXQ 的回复:
public static void main(String[] args) { String[] text=new String[]{"<$>","ss","aa","<$>"}; int count=-1; for (String string : text) { count++; if(string.equals("<$>")){ text[count]=string+"<$>"; } } for (String string : text) { System.out.println(string); } } 求采纳,谢谢
谢谢!,但题目描述中提到不能用字符串的方法,如equals
qq_29448025 2017-06-21
  • 打赏
  • 举报
回复
引用 3 楼 u014034934 的回复:

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);
		}
		
	}
谢谢!,但题目描述中提到不能用字符串的方法,如equals
拘谨的小人 2017-06-21
  • 打赏
  • 举报
回复
replace
csdnSXQ 2017-06-19
  • 打赏
  • 举报
回复
public static void main(String[] args) { String[] text=new String[]{"<$>","ss","aa","<$>"}; int count=-1; for (String string : text) { count++; if(string.equals("<$>")){ text[count]=string+"<$>"; } } for (String string : text) { System.out.println(string); } } 求采纳,谢谢
严兵123 2017-06-19
  • 打赏
  • 举报
回复
看来大家都懒得回复,java基础啊。还是要注重基础的培养
逗比123号 2017-06-19
  • 打赏
  • 举报
回复

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

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧