????????2????????鳤???????????????????
public class FunctionDemo {
public static void main(String[] args){
int[] arr = new int[]{1??9??6};
int sum = 0;
System.out.println("length="+arr.length);//??????鳤??
for(int x=0;x<arr.length;x++){
sum+=arr[x];//??????????????????
System.out.println("arr["+x+"]"+"="+arr[x]);
}
System.out.println("sum="+sum);
}
}//??????????length=3
arr[0]=1
arr[1]=9
arr[2]=6
sum=16
????????3??????????????е??????м?????????????????????????????????????????????????????????
public class FunctionDemo {
public static void main(String[] args){
int[] arr = new int[]{1??9??6};
printArry(arr);//printArray????????????????Щ?????????????????????????飬???е??ü??ɡ?
}
public static void printArry(int[] arr){
int sum = 0;
for(int x=0;x<arr.length;x++){
if(x!=arr.length-1)//?????????????????????
System.out.print(arr[x]+"??");
else{System.out.print(arr[x]);}
sum+=arr[x];
}
System.out.println();
System.out.println("sum="+sum);
}
}
????????4??e??????
public class FunctionDemo {
public static void main(String[] args){
int[] arr = new int[]{1??9??6};
//???????
printArry(arr);
//????
bubbleSort(arr);
//?????
printArry(arr);
}
public static void printArry(int[] arr){
for(int x=0;x<arr.length;x++){
if(x!=arr.length-1)
System.out.print(arr[x]+"??");
else{System.out.print(arr[x]);}
}
System.out.println();
}
public static void bubbleSort(int[] arr){
for(int x=0;x<arr.length-1;x++){
for(int y = 0;y<arr.length-x-1;y++){//-x????????????α??????????-1????????????????硣
if(arr[y]>arr[y+1]){
int temp = arr[y];
arr[y] = arr[y+1];
arr[y+1] = temp;
}
}
}
}
}