当前位置:编程学习 > JAVA >>

求高手指点!!

今天去面试,遇到了几个问题,求指点:
第一个:

第二个:
原题:List<Integer> s(String str,String s);
用List返回字符串str中字符串s的角标位置;
(如:str="absfyughsfhg",s="sf") --------------------编程问答-------------------- A.this.i --------------------编程问答-------------------- 第一题: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;
}
}
--------------------编程问答-------------------- 除 --------------------编程问答-------------------- 第一个:A.this --------------------编程问答-------------------- 第一题算类中类?。 --------------------编程问答-------------------- class嵌套吗 --------------------编程问答-------------------- 用outer.this.i --------------------编程问答--------------------
引用 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;
}
}

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

第二个问题这个回答就很好了 --------------------编程问答--------------------
引用 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;
}
}

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

第二个问题这个回答就很好了

--------------------编程问答--------------------
引用 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;
}
}

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

第二个问题这个回答就很好了


之前的2楼代码如果测试下会发现有问题,改成这个版本后应该可以
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,