package com.atguigu;public class Fanzhuan { public static void main(String[] args) { //數組的反轉 //方法一 String[] arr=new String[]{"JJ","DD","MM","BB","GG", ...
package com.atguigu;
public class Fanzhuan {
public static void main(String[] args) {
//數組的反轉
//方法一
String[] arr=new String[]{"JJ","DD","MM","BB","GG","AA"};
for(int i=0;i<arr.length/2;i++){
String temp=arr[i];
arr[i]=arr[arr.length-i-1];
arr[arr.length-i-1]=temp;
}
//方法二
for(int i=0,j=arr.length-1;i<j;i++,j--){
String temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+'\t');
}
}
}