You have a table of integer numbers. You should rotate rows of the table by the specified distance.
Try to use collections and standard methods for them.
Input data format
The first line contains two numbers: a number of rows and a number of columns of the table.
The following lines describe rows of the table. In each row, all elements are separated by spaces.
The last line consists of one number, which is the distance for rotating.
Output data format
Output the resulting table. Separate numbers by a single space in the output.
Report a typo
Sample Input 1:
3 3
1 1 1
2 2 2
3 3 3
1
Sample Output 1:
3 3 3
1 1 1
2 2 2
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<String> list = new ArrayList<>();
int rowsAndCols = Integer.parseInt(sc.nextLine().split(" ")[0]);
for (int i = 0; i < rowsAndCols; i++) {
list.add(sc.nextLine());
}
Collections.rotate(list, sc.nextInt());
list.forEach(System.out::println);
}
}
The utility class Collections Rotating table
原文:https://www.cnblogs.com/longlong6296/p/13740893.html