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;i<str.length-1;i++){
for (int j=i+1;j<str.length-1;j++){
if(str[i]>str[j])
{
int temp;
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}
}
for(int j=0;j<str.length;j++)
{
System.out.print(str[j]);
System.out.print(',');
}
}
}
谢谢
解决方案 »
- 请问jsp中怎么设计表格
- 关于在线支付的问题,期待高手解答。
- 谁能教我配置tomcat环境?
- 关于tomcat“java.net.SocketException: Connection reset by peer: socket write error”的错误
- 关于LDAP的问题
- webservice
- 为什么我在Servlet中放置在session对象中的ArrayList对象在JSP页中取不出来!
- 一个奇怪的问题请各位帮帮忙(马上结帐)
- web服务器是不是得到所有post的数据后才把request传给servlet?
- 修改TOMCAT 的server.xml的 Context进行WEB部署
- FCKeditor单引号的问题
- org.apache.commons.fileupload 文件上传简单问题,楞是没解决,求救!!!顶贴有分!
for (int j=i+1;j<str.length-1;j++){
if(str[i]>str[j])
看清楚了,里面的循环的起始值j是i+1的,若有外循环上不设置个 i<str.length-1,
当i==str.length-1时,那j是啥值?不就是str.length吗?
那str[j]呢?不就出超出数组的大小范围了吗?