〆会者


私信TA

用户名:uq_92166979982

访问量:665

签 名:

等  级
排  名 15115
经  验 802
参赛次数 0
文章发表 4
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

注意事项:

要注意   int m = scanner.nextInt();
              scanner.nextLine();要加一个空的,否则会自动跳过String s的读取
             String s = scanner.nextLine();

20190724221539763.png

参考代码:

public class 交换easy {
   public static void main(String[] args) {
       Scanner scanner=new Scanner(System.in);
       int n = scanner.nextInt();
       int m = scanner.nextInt();
       scanner.nextLine();
       String s = scanner.nextLine();
       String[] split = s.trim().split("\\s");
for (int x1=0;x1<m;x1++) {
   int x = scanner.nextInt() - 1;
   int y = scanner.nextInt() - 1;
   String t = split[x];
   split[x] = split[y];
   split[y] = t;
}
       for (int i = 0; i <n; i++) {
           System.out.println(split[i]);
       }
           }
       }

 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区