import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
public class GetNode {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
List<Integer> list = new ArrayList<Integer>();
int []arr = new int[num];
while (num>0) {
list.add(scan.nextInt());
num--;
}
int out = scan.nextInt();
Iterator<Integer> it = list.iterator();
int count = 0;
while(it.hasNext()){
arr[count++] = it.next();
}
System.out.println(arr[arr.length-out-1]);
}
}
方法二:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class GetNode {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
List<Integer> list = new ArrayList<Integer>();
int a = num-1;
while (num>0) {
list.add(scan.nextInt());
num--;
}
int out = scan.nextInt();
while (out>0) {
list.remove(a--);
out--;
}
System.out.println(list.get(a));
}
}