public class Arr2 {
public static void main(String[] args) {
int b[]={13,21,1,2,5,6};
int c;
for(int j=0;j<b.length-1;j++){
for(int i=0;i<b.length-1;i++){
if(b[i]>b[i+1]){
c=b[i+1];
b[i+1]=b[i];
b[i]=c;
}}
}
for(int i=0;i<b.length;i++){
System.out.println(b[i]);
}
}
}
上面的代码是从小到大顺序输出数组
public class Arr1 {
public static void main(String[] args) {
int arr[]=new int[5];
Scanner sc=new Scanner(System.in);
System.out.println("请输入数组元素");
for(int i=0;i<5;i++) {
arr[i] = sc.nextInt();
}
System.out.println("遍历后的数组为");
for(int j=0;j<arr.length;j++)
{
System.out.print(arr[j]+",");
}
}
}
上面是JAVA遍历数组
public class Arr3 {
public static void main(String[] args) {
int a[][]={{1,4,2},{45,23,65,98},{90,213,45,67,8},{987,90}};
System.out.println("二维数组遍历");
for(int i=0;i<a.length;i++){
for(int j=0;j<a[i].length;j++){
System.out.print(a[i][j]+",");
}
}
}
}
二维数组的遍历