package fr.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public static void main(String[] args) throws IOException {
BufferedReader lecteur = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(lecteur.readLine());
int m = Integer.parseInt(lecteur.readLine());
ArrayList<String> liste = new ArrayList<>(n);
for(int i =0; i<n;i++){
String s = lecteur.readLine();
liste.add(s);
}
liste.addAll(liste.size(),liste.subList(0,m));
for(String s : liste){
System.out.println(s);
}
}
HugoAl
Niveau 23
Why it does not work ??
Discussion en cours
Commentaires (2)
- Populaires
- Nouveau
- Anciennes
Tu dois être connecté(e) pour laisser un commentaire
Guadalupe Gagnon
10 août 2022, 15:08
Up to line 20 your code works as instructed. Line 21 does not move the first element to the end of the list M times. The validation test that you literally remove the first element and place it to the end of the list the required amount of times. So if I had simple list with elements {1, 3, 2} and M was 4 then the line that is now 21 in your code should do these 4 steps:
1) remove 1 and move it to the end, so list is now {3, 2, 1}
2) remove 3 and move it to the end, so list is now {2, 1, 3}
3) remove 2 and move it to the end, so list is now {1, 3, 2}
4) remove 1 and move it to the end, so list is now {3, 2, 1}
+1
HugoAl Full Stack Developer
11 août 2022, 10:39
Yes this morning after a good night. I told i'm stupid, i did not what was expected 😓.
0