import java.util.Scanner ;
public class Main {
public static void main ( String[] args ) {
Scanner sc = new Scanner ( System.in ) ;
int[] number = new int [100] ; // 設定一個元素數量為100的「int」陣列
int amount = 0 ; // 輸入的數字數量,同時兼具陣列的元素位置
// 如果有下一筆資料就繼續輸入,沒有則離開( Ctrl Z )
while ( sc.hasNext () ) {
number[amount] = sc.nextInt () ; // 輸入數字
amount += 1 ; // 數量加一,同時也代表下一個元素的位置
}
// 進行反轉
int seat = amount - 1 ; // 由後往前,初始化為「最後的元素位置」
for ( int element = 0 ; element < seat ; element += 1 ) {
// 將相對應的數字進行交換
int test = number[element] ;
number[element] = number[seat] ;
number[seat] = test ;
seat -= 1 ; // 下一個位置
}
// 顯示反轉後的數字陣列
for ( int element = 0 ; element < amount - 1 ; element += 1 ) {
System.out.print ( number[element] + " " ) ;
}
System.out.println ( number[ amount - 1 ] ) ;
}
}
留言列表