今天复习了下冒泡排序和选择排序
这是代码
package a20200715;
import java.util.Arrays;
public class a20200715 {
public static void main(String[] args) {
int[] a={1,5,6,9,8,2,3};
int i,j,t;
System.out.println(Arrays.toString(a));
for(i=0;i<a.length-1;i++)
{
for(j=0;j<a.length-i-1;j++)
{if(a[j]>a[j+1]) {
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
System.out.println(Arrays.toString(a));
}
}
package a20200715;
import java.util.Arrays;
public class b20200715 {
public static void main(String[] args) {
int[] a={1,5,6,9,8,2,3};
int i,j,t;
System.out.println(Arrays.toString(a));
for(i=0;i<a.length-1;i++)
{
for(j=i+1;j<a.length;j++) {
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
System.out.println(Arrays.toString(a));
}
}