import java.io.*;
public class SelectionSort
{
public static void main(String args[])
throws IOException
{
BufferefReader br = new BufferedReader (new
InputStreamReader(System.in);
a[i] = Integer.parseInt(args[i]);
}
print(a);
SelectionSort(a);
print(a);
}
private static void SelectionSort(int[] a)
{
int min,temp;
for(int l=0;l<=a.length;l--)
for(int i=0;i<a.length;i++){
min = i;
for(int k=min+1;k<a.length;k++){
if (a[i]<a[min])
{
min = i;
{
}
}
if (min != i)
{
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
}
} private static void print(int[] a)
{
for(int i=0;i<a.length;i++){
System.out.print(" "+a[i]);
}
System.out.println();
}
}
Please input the number which you wanna search :214
the num which you input is not exsit in the arraythe [2]:214the num which you i
put is not exsit in the arraythe num which you input is not exsit in the arrayt
e num which you input is not exsit in the arraythe num which you input is not e
sit in the arraythe num which you input is not exsit in the arraythe num which
ou input is not exsit in the arraythe num which you input is not exsit in the a
raythe num which you input is not exsit in the arraythe num which you input is
ot exsit in the arrayException in thread "main" java.lang.ArrayIndexOutOfBounds
xception: 10
at LinerSearch.main(LinerSearch.java:18)
自己做了些修改程序快范围的尝试 还是没结果所以求结果和优化 谢谢啦
public class SelectionSort
{
public static void main(String args[])
throws IOException
{
BufferefReader br = new BufferedReader (new
InputStreamReader(System.in);
a[i] = Integer.parseInt(args[i]);
}
print(a);
SelectionSort(a);
print(a);
}
private static void SelectionSort(int[] a)
{
int min,temp;
for(int l=0;l<=a.length;l--)
for(int i=0;i<a.length;i++){
min = i;
for(int k=min+1;k<a.length;k++){
if (a[i]<a[min])
{
min = i;
{
}
}
if (min != i)
{
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
}
} private static void print(int[] a)
{
for(int i=0;i<a.length;i++){
System.out.print(" "+a[i]);
}
System.out.println();
}
}
Please input the number which you wanna search :214
the num which you input is not exsit in the arraythe [2]:214the num which you i
put is not exsit in the arraythe num which you input is not exsit in the arrayt
e num which you input is not exsit in the arraythe num which you input is not e
sit in the arraythe num which you input is not exsit in the arraythe num which
ou input is not exsit in the arraythe num which you input is not exsit in the a
raythe num which you input is not exsit in the arraythe num which you input is
ot exsit in the arrayException in thread "main" java.lang.ArrayIndexOutOfBounds
xception: 10
at LinerSearch.main(LinerSearch.java:18)
自己做了些修改程序快范围的尝试 还是没结果所以求结果和优化 谢谢啦
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货