大家好,我正在尝试通过解决ACM中的一些问题来提高我的Java技能,现在问题是我的示例输入如下所示:
3 100
34 100
75 250
27 2147483647
101 304
101 303
-1 -1
Run Code Online (Sandbox Code Playgroud)
所以起初我只是想尝试阅读它们,但它在这里不起作用的是java代码:
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner stdin = new Scanner(new BufferedInputStream(System.in));
while (stdin.hasNext()) {
System.out.println(stdin.nextInt() + " and the next " + stdin.nextInt());
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试图将这些输入作为参数发送,而不是通过从文件中读取它们,这是如何:
替代文字http://i41.tinypic.com/j61npu.gif
该程序只是旋转(执行)但不打印任何东西.我怎样才能解决这个问题?
您在向导中指定的参数不会通过std输入到程序中.而是通过String[] args传递给main方法的参数传入它们.看起来您在Eclipse中运行,您可以转到生成的Console选项卡并输入该窗口.或者,您可以遍历args参数以获取这些值.