题解 | 单组_二维字符数组-Java
单组_二维字符数组
https://www.nowcoder.com/practice/2316c1fedff14a8d91694a26c9da3310
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int n = in.nextInt();
int m = in.nextInt();
StringBuilder sb = new StringBuilder();
while (in.hasNextLine()) { // 注意 while 处理多个 case
String s = in.nextLine();
sb.append(s);
}
char[] res = sb.reverse().toString().toCharArray();
for (int i = 0; i < n * m; i++) {
System.out.print(res[i]);
if ((i + 1) % m == 0) {
System.out.println();
}
}
}
}
