x = [ 3 , 4 , 9 , 6 , 2 ] ( x.length / 2 ).times { |i| # x[ i ] と x[ x.length-i-1 ]を交換する work = x[ i ] x[ i ] = x[ x.length-i-1 ] x[ x.length-i-1 ] = work } x.length.times { |i| printf( "x[ %d ] = %d\n" , i , x[ i ] ) }