The problem dies in the second loop, which did not remove the last few strings as I thought.
package zh.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
及时洗牌
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
String s1 = reader.readLine();
String s2 = reader.readLine();
int N = Integer.parseInt(s1);
int M = Integer.parseInt(s2);
for (int i = 0; i < N;i++)
{
String s = reader.readLine();
list.add(s);
}
for (int j = 0; j < M ;j++)
{
String s = list.get(j);
list.add(s);
list.remove(j);
}
for (int k = 0; k < list.size();k++)
{
System.out.println(list.get(k));
}//在此编写你的代码
}
}