AcWing 816. 数组翻转 - Java
原题链接
简单
作者:
KYCygni
,
2021-03-26 09:27:23
,
所有人可见
,
阅读 265
Java 代码
import java.util.Scanner;
public class Main
{
public static void reverse(int[] nums, int size)
{
int[] t = new int[size];
for (int i = 0; i < size; i ++)
t[i] = nums[size -1 - i];
for (int j = 0; j < size; j ++)
nums[j] = t[j];
}
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int size = cin.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i ++)
nums[i] = cin.nextInt();
reverse(nums, size);
for (int j = 0; j < n; j ++)
System.out.print(nums[j] + " ");
}
}