public class arr2{ publicstaticvoidmain (string [ ] args ) intb [ ]={ 13,21,1,2,5,6 }; int c; for(intj=0; jb.length-1; j ) for(intI=0; ib.length-1; I () if ) b[I]b[I1] ) {c=b[i 1]; b[i 1]=b[i]; b[i]=c; }}for(intI=0; ib.length; I ) system.out.println(b[I]; }}上面的代码按从小到大的顺序输出数组
public class arr1{ publicstaticvoidmain (字符串[ ] args ) {int arr[]=new int[5]; sannersc=newscanner(system.in; System.out.println ('请输入数组元素); for(intI=0; i5; I () {arr[i]=sc.nextInt ); }System.out.println ('扫描后的数组为'); for(intj=0; jarr.length; j ) (system.out.print ) ARR[j] ),); }}上面是JAVA遍历数组
public class arr3{ publicstaticvoidmain [ string [ ] args ] { inta [ ]={ 1,4,2 },{ 45,23,65,98 },{ 90,228 } for(intI=0; ia.length; I ) for(intj=0; ja[i].length; j ) (system.out.print ) a[I][j],'); } }遍历二维数组