我这里有一点烦人的情况; 其中我无法正确接受输入.我总是接受输入Scanner,而不习惯BufferedReader.
输入格式
First line contains T, which is an integer representing the number of test cases.
T cases follow. Each case consists of two lines.
First line has the string S.
The second line contains two integers M, P separated by a space.
Run Code Online (Sandbox Code Playgroud)
例
Input:
2
AbcDef
1 2
abcabc
1 1
Run Code Online (Sandbox Code Playgroud)
我的代码到目前为止:
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
int T= Integer.parseInt(inp.readLine());
for(int i=0;i<T;i++) {
String s= inp.readLine();
int[] m= new int[2];
m[0]=inp.read();
m[1]=inp.read();
// Checking whether I am taking the inputs correctly
System.out.println(s);
System.out.println(m[0]);
System.out.println(m[1]);
}
}
Run Code Online (Sandbox Code Playgroud)
当输入上面显示的示例时,我得到以下输出:
AbcDef
9
49
2
9
97
Run Code Online (Sandbox Code Playgroud)
Sub*_*der 14
BufferedReader#read 从流中读取单个字符[0到65535(0x00-0xffff)],因此无法从流中读取单个整数.
String s= inp.readLine();
int[] m= new int[2];
String[] s1 = inp.readLine().split(" ");
m[0]=Integer.parseInt(s1[0]);
m[1]=Integer.parseInt(s1[1]);
// Checking whether I am taking the inputs correctly
System.out.println(s);
System.out.println(m[0]);
System.out.println(m[1]);
Run Code Online (Sandbox Code Playgroud)
您还可以检查Scanner与BufferedReader.
| 归档时间: |
|
| 查看次数: |
178512 次 |
| 最近记录: |