int[] a={5,2,3,4,1,6,7,8,9}; boolean flag=true; int t=0; for(int j=0;j<a.length-1;j++) { for(int i=0;i<a.length-i-1;i++) { if(a[i]>a[i+1]) { t=a[i]; a[i]=a[i+1]; a[i+1]=t; flag=false; } if(flag==true) { break; } } } System.out.println(Arrays.toString(a)); |
原文地址:https://www.cnblogs.com/lwd521/p/11450902.html
时间: 2024-10-23 06:28:54