求高手指点!!

键盘客 2013-08-28 04:45:05
今天去面试,遇到了几个问题,求指点:
第一个:

第二个:
原题:List<Integer> s(String str,String s);
用List返回字符串str中字符串s的角标位置;
(如:str="absfyughsfhg",s="sf")
...全文
162 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiyanghan2012 2013-08-29
  • 打赏
  • 举报
回复
用outer.this.i
LinuxMonster 2013-08-29
  • 打赏
  • 举报
回复
class嵌套吗
异常异长 2013-08-29
  • 打赏
  • 举报
回复
第一题算类中类?。
linhu007 2013-08-29
  • 打赏
  • 举报
回复
第一个:A.this
风扇不摇头9 2013-08-29
  • 打赏
  • 举报
回复
引用 9 楼 u011483829 的回复:
[quote=引用 8 楼 u011483829 的回复:] [quote=引用 2 楼 fudongrifdr 的回复:] 第一题:A.this.i 第二题
public class Test {
	public static void main(String[] args) {
		System.out.println(s("absfyughsfhg","sf"));
	}
	public static List<Integer> s(String str, String s) {
		List<Integer> position = new ArrayList<Integer>();
		for(int i=0;i<str.length();i++) {
			int y = str.indexOf(s,i);
			if(-1 == y) {
				break;
			}else {
				position.add(y);
				i+=y;
			}
			

		}
		return position;
	}
}
第一个是内部类可以共享外部类的属性 第二个问题这个回答就很好了[/quote] [/quote] 之前的2楼代码如果测试下会发现有问题,改成这个版本后应该可以
风扇不摇头9 2013-08-29
  • 打赏
  • 举报
回复
引用 8 楼 u011483829 的回复:
[quote=引用 2 楼 fudongrifdr 的回复:]
第一题:A.this.i
第二题
public class Test {
public static void main(String[] args) {
System.out.println(s("absfyughsfhg","sf"));
}
public static List<Integer> s(String str, String s) {
List<Integer> position = new ArrayList<Integer>();
for(int i=0;i<str.length();i++) {
int y = str.indexOf(s,i);
if(-1 == y) {
break;
}else {
position.add(y);
i+=y;
}


}
return position;
}
}

第一个是内部类可以共享外部类的属性

第二个问题这个回答就很好了[/quote]
风扇不摇头9 2013-08-29
  • 打赏
  • 举报
回复
引用 2 楼 fudongrifdr 的回复:
第一题:A.this.i
第二题
public class Test {
public static void main(String[] args) {
System.out.println(s("absfyughsfhg","sf"));
}
public static List<Integer> s(String str, String s) {
List<Integer> position = new ArrayList<Integer>();
for(int i=0;i<str.length();i++) {
int y = str.indexOf(s,i);
if(-1 == y) {
break;
}else {
position.add(y);
i+=y;
}


}
return position;
}
}

第一个是内部类可以共享外部类的属性

第二个问题这个回答就很好了
末日哥 2013-08-28
  • 打赏
  • 举报
回复
第一题:A.this.i 第二题
public class Test {
	public static void main(String[] args) {
		System.out.println(s("absfyughsfhg","sf"));
	}
	public static List<Integer> s(String str, String s) {
		List<Integer> position = new ArrayList<Integer>();
		for(int i=0;i<str.length();i++) {
			int y = str.indexOf(s,i);
			if(-1 == y) {
				break;
			}else {
				position.add(y);
				i+=y;
			}
			

		}
		return position;
	}
}
bayougeng 2013-08-28
  • 打赏
  • 举报
回复
A.this.i

62,614

社区成员

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

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