当前页面: 开发资料首页 → JSP 专题 → 有人知道吗?什么情况下for(int i=0;i-lt;str.length-1;i++)里面的str.length-1是减1的。大部分小于str.length就可以了吗
摘要: 有人知道吗?什么情况下for(int i=0;i
public class A {
public static void main(String[] args) {
int[] str={3,5,4,6,2,33,35};
int a,b;
for(int i=0;ifor (int j=i+1;j
if(str[i]>str[j])
{
int temp;
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}
}
for(int j=0;j{
System.out.print(str[j]);
System.out.print(',');
}
}
}
谢谢
for(int i=0;ifor (int j=i+1;j if(str[i]>str[j])
看清楚了,里面的循环的起始值j是i+1的,若有外循环上不设置个 i当i==str.length-1时,那j是啥值?不就是str.length吗?
那str[j]呢?不就出超出数组的大小范围了吗?