一开始我是用index 去接收最后一个数,
结果remove使用的是index参数,变成删掉指定索引,而不是删除值
所以要用object接收最后一个数
这样才会删除指定数值

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<>();
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int v = in.nextInt();
            list.add(v);
            for(int i=0;i<n - 1;i++){
                int n1 = in.nextInt();
                int n2 = in.nextInt();

                int index = list.indexOf(n2);
                list.add(index + 1,n1);
            }
            Object rmv = in.nextInt();
            list.remove(rmv);
            for(Integer va : list){
                System.out.print(va + " ");
            }
        }
    }
}