java的下面图的代码到底怎么回事,运行结果完全不一样
packageMyDream3;importjava.util.Vector;publicclassTestVector02{publicstaticvoidmain(S...
package MyDream3;
import java.util.Vector;
public class TestVector02 {
public static void main(String[] args) {
Vector<String> s=new Vector<String>(100);
for(int i=0;i<3;i++) {
s.addElement("Welcome");
s.addElement("to");
s.addElement("jing");
}
for(int i=0;i<s.size();i++) {
String s1=s.elementAt(i);
System.out.print(s+" ");
}
System.out.println();
if(s.removeElement("to"))
for(int i=0;i<s.size();i++) {
String s2=s.elementAt(i);
System.out.println(s2);
}
}
}
运行结果:
[Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing]
Welcome
jing
Welcome
to
jing
Welcome
to
jing
如果你把倒数第一个循环语句上面的那个语句if换成while,再把;去掉,结果又不一样了 展开
import java.util.Vector;
public class TestVector02 {
public static void main(String[] args) {
Vector<String> s=new Vector<String>(100);
for(int i=0;i<3;i++) {
s.addElement("Welcome");
s.addElement("to");
s.addElement("jing");
}
for(int i=0;i<s.size();i++) {
String s1=s.elementAt(i);
System.out.print(s+" ");
}
System.out.println();
if(s.removeElement("to"))
for(int i=0;i<s.size();i++) {
String s2=s.elementAt(i);
System.out.println(s2);
}
}
}
运行结果:
[Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing] [Welcome, to, jing, Welcome, to, jing, Welcome, to, jing]
Welcome
jing
Welcome
to
jing
Welcome
to
jing
如果你把倒数第一个循环语句上面的那个语句if换成while,再把;去掉,结果又不一样了 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询