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>();
System.out.println("Enter the length of the list: ");
String s= reader.readLine();
int n=Integer.parseInt(s);
System.out.println("Enter the numbers you want to move: ");
String a= reader.readLine();
int m=Integer.parseInt(a);
for(int i=0;i<n;i++){
String string= reader.readLine();
list.add(string);
}
for(int i=0;i<m;i++){
String temp=list.get(0);
list.remove(list.get(0));
list.add(list.size(),temp);
}
for(String string:list){
System.out.println(string);
}
}
}
catalin1989
Level 37
Works fine in IntelliJ but doesn't pass the test. Can someone give me a hint why?
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
catalin1989
20 September 2023, 15:52
• Declare a string list variable and immediately initialize it.
• Read numbers N and M from the keyboard. Read N strings and add them to the list.
• Move the first M strings to the end of the list.
• Display the list, each value on a new line.
this are the tasks required.
0
Guadalupe Gagnon
19 September 2023, 13:13
Did the task say to output:
"Enter the length of the list: " and "Enter the numbers you want to move: "
The validation does test the output and if the task conditions did not specify to output those lines then they would automatically cause a fail.
0