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); } } }