package pl.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Przestawiono w samą porę
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//tutaj wpisz swój kod
ArrayList<String> lista = new ArrayList<>();
int n = Integer.parseInt(reader.readLine());
int m = Integer.parseInt(reader.readLine());
for(int i =0; i<n; i++)
{
lista.add(reader.readLine());
}
for(int i =0; i<m; i++) {
lista.add(lista.get(i));
lista.remove(i);
}
for(String x : lista)
{
System.out.println(x);
}
}
}
Could you explain what's wrong?
Dyskutowane
Komentarze (3)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Magda
5 lutego, 11:06
Still don't have idea how to fix it.
I thought if I had copied the number at index i, place it at the end and remove(i) m amounts of time, the programme would be working
int move = array.get(i)
array.remove(i)
array.add(move)
(m amounts of time)
0
Thomas
6 lutego, 08:43przydatny
As Lupe already mentioned, you need to remove the first element in the list.
api docs
in addition to just removing an entry this method also returns the value stored at the index you pass to it.
now you just need to take care of adding to the end...
or you even can combine the two method calls
When you're looking for methods or how they are called you always can peek into the +2
Guadalupe Gagnon
1 lutego, 18:33
You should be adding and removing the first item in the list M amount of times. This code does not do this and instead adds and removes the value at index i. If M is greater than N then an Exception will be thrown when i is greater than list.length().
+1