【发布时间】:2015-05-14 22:18:01
【问题描述】:
我正在解决关于代码厨师的问题。我遇到了一个问题,它所说的只是我有错误的答案。我想测试我的程序以查看其输出,但它从文本文件中读取输入,我无法弄清楚如何使用 eclipse 来执行此操作,我的代码如下:
import java.io.*;
class Holes {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int testCases = Integer.parseInt(r.readLine());
for (int i =0; i<testCases; i++)
{
int holes = 0;
String s = r.readLine();
for (int j= 0; j< s.length(); j++)
{
char c = s.charAt(j);
if (c == 'B')
holes += 2;
else if (c== 'A' || c== 'D' ||c== 'O' ||c== 'P' ||c== 'Q' ||c== 'R' )
{
holes +=1;
}
System.out.println(holes);
}
}
}
}
【问题讨论】:
-
2008 年有一个类似的问题,基本上说最好的方法是使用命令行,但我希望从那时起 eclipse 已经添加了该功能。
-
看看filereader和scanner for file i/o。 stackoverflow.com/questions/4716503/…
-
我使用 System.in 而不是 console.in??