public class JPA505 {
public static void main(String[] argv) {
String[] data = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
System.out.print("反轉陣列資料之前: ");
for(int i=0;i<data.length;i++){
System.out.print(" "+data[i]);
}
System.out.println();
reverse(data);
System.out.print("反轉陣列資料之後: ");
for(int i=0;i<data.length;i++){
System.out.print(" "+data[i]);
}
System.out.println();
}
public static void reverse(String a[]) {
String tmp;
int i=0;
int j=(a.length-1);
while(i<(a.length/2)){
tmp=a[i];
a[i]=a[j];
a[j]=tmp;
i++;
j--;
}
}
}
505 反轉陣列
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言