【发布时间】:2015-06-03 09:25:05
【问题描述】:
这是我的代码,它只是从输入流中读取行并显示它们,但令我惊讶的是它没有读取所有行。它的读数只到倒数第二行。
这是我的代码:-
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
short n = scan.nextShort();
short m = scan.nextShort();
byte[][] topics = new byte[n][m];
for(short i = 0; i < n; i++){
char[] arr = scan.nextLine().toCharArray();
display(arr);
}
}
private static void display(char[] arr){
for(int i = 0; i < arr.length; i++){
System.out.print(arr[i]);
}
System.out.println();
}
}
输入以这种格式给出
4 5
10101
11100
11010
00101
我的输出是这样的:-
10101
11100
11010
它没有第三行。为什么?
【问题讨论】:
-
@TheLostMind 我只是复制粘贴了输出,所以你也可以看到输出。
标签: java java.util.scanner inputstream