import java.math.*;
public class selectarithmetic
{
public static void main(String args[]) //throws Exception(e)
{
int i,temp,j;
int array[] = {4,2,45,64,22,64,8,64,15};
for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)
if(array[j]>array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
System.out.println("排序后的数为:");
for(j=0;j<9;j++)
{
System.out.println("ee"+array[j]);
}
}}
public class selectarithmetic
{
public static void main(String args[]) //throws Exception(e)
{
int i,temp,j;
int array[] = {4,2,45,64,22,64,8,64,15};
for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)
if(array[j]>array[j+1])
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
System.out.println("排序后的数为:");
for(j=0;j<9;j++)
{
System.out.println("ee"+array[j]);
}
}}
解决方案 »
- 合代码,优化java代码
- request.getRequestDispatcher问题
- 有人测过1.4和1.5的虚拟机的性能吗?居然差几十倍?怎么回事儿?
- 求助:jboss下如何件将web、应用、数据库三服务器部署在三电脑上?
- java 中如何从LIST 对象取值
- 开源项目是什么,要做的话具体怎样实施?
- 安装设置Java环境
- 关于使用SDK的编译器时出现的错误提示,请大虾帮我解释一下并给出解决办法。
- 100分请教java怎样播放rm文件
- 我是java的super级初学者,也就是骨灰级菜鸟 谁知道有什莫学习java的 经典教材 (请指教)
- 面试了个JAVA的题,大家帮忙看看!
- 用java处理图片,在图片右下角加一段文字,并且设置文字的颜色,和文字的背景色
int array[] = {4,2,45,64,22,64,8,64,15};
for(i=0;i <9;i++)
{
for(j=0;j <9-i;j++) if(array[j]>array[j+1]) // 这里是两个j?
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
public static void main(String args[]) // throws Exception(e)
{
int i, temp, j;
int array[] = { 4, 2, 45, 64, 22, 64, 8, 64, 15 };
for (i = 0; i < 9; i++) {
for (j = 0; j < 8 - i; j++) //9-i时,数组发生越界了啊,我这里改成了8-i,能实现你要的效果
if (array[j] > array[j + 1]) {
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
System.out.println("排序后的数为:");
for (j = 0; j < 9; j++) {
System.out.println("ee" + array[j]);
} }
{
for(j=0;j <array.length-i;j++) 建议楼主这么写