• 周四. 10 月 3rd, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Java introduction 1 reverse array

King Wang

1 月 3, 2022
package day5;
public class fanzhuanjiaohuan {

public static void main(String[] args) {

int[] arr = {
11,22,3,4,5};
reverse(arr);
printArrarry(arr);
}
/**
* Inversion array
* @param arr
*/
public static void reverse(int[] arr){

int length = arr.length -1;
for (int start = 0,end = length;start<=end;start++,end--){

int tmp = arr[start];
arr[start] = arr[end];
arr[end] = tmp;
}
}
/**
* Output array
* @param arr
*/
public static void printArrarry(int[] arr){

System.out.print("[");
for (int i=0;i<arr.length;i++){

if(i == arr.length-1){

System.out.print(arr[i]);
}else{

System.out.print(arr[i]+",");
}
}
System.out.print("]");
}
}

发表回复