问题标签 [system.in]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 使用扫描仪 - 在 java.util.Scanner.next(Unknown Source) java.util.NoSuchElementException
我的完整代码粘贴在这里。以下是与我的问题相关的两种方法。
我已经尝试了许多如何阅读一个字符的组合。这曾经有效,我可以使用以下方法读取一个字符:
但是,不知何故,在我编写的这个程序中,它不起作用。
这是一个程序,它将读取 5 个用户名(字符串)和 5 个分数(整数)并将它们放入 2 个数组中。它将按降序对数组进行排序,然后将它们打印出来。所以,我唯一的问题是问他们是否想再玩一次并输入一些字符来看看他们是否想再玩一次(y/n)?
如果可以的话请帮忙。我尝试了许多组合:if (input.hasNext())
,但无济于事。
java - Java redirecting System.in - InputStream.read called but nothing "returned"
So I'm trying to redirect a textbox to System.in. I've seen this thread Redirect System.in to swing component , and seem to have everything working:
The reads seem to be executing properly: I have a helper
And I call
So the "Read called: returning #"
is printed. I get the proper character codes followed by the final -1 when I call something. The read method blocks until input is ready, as the docs specify.
However, I only get the "Read called..."
messages, and the next line ("You said...
") never executes (it's stuck still reading). I can't for my life figure out what the problem is - If you want to see more code (although I think the "Read called..."
messages show it's doing the right thing) just let me know.
Is there something else I should do to be able to call readLine
and get the input from a textbox? I also tried overriding the other methods in inputstream without luck (again, the read
method is executing properly)
java - 在 Eclipse 中输入“System.in.read()”
当您在 Eclipse 中读取标准输入时,该输入来自哪里?
java - 为什么 Java System.in.read() 可以调用不是静态方法
在java中,类java.lang.System
,其中有一个静态变量。
声明为:public static final InputStream in这意味着in是一个 InputStream 变量。
但是我看到了一些例子,
用于读取输入。
System.in.read()
怎么会这样,read()
InputStream中的方法不是静态方法,怎么能直接调用呢?据我了解,只有静态方法才能由类直接调用而无需创建实例。
read() 声明:public abstract int read() throws IOException
谢谢 Jon Skeet 的回答,我还有点不明白。
如果我调用System.in.read()
这意味着我调用 InputStream 类方法read()
?
- 调用
java.lang.System.in
(这是一个静态变量),in是一个java.io.InputStream
变量 - 调用行为类似于调用 PrintStream 类。
- 该过程像调用一样工作:
PrintStream.read()
- 但是我很难理解 read() 方法,它不是静态方法,因为它不应该直接调用。
它应该像这样调用:
PrintStream rd = new PrintStream(); int c = rd.read();
因为 read() 应该由实例调用。read() 声明:public abstract int read() throws IOException
PS:我尝试此代码不起作用:
但不知道为什么。
参考:http ://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html
java - System.in 指向 JtextArea 并使用 Scanner 导致应用程序挂起
我有一个 JFrame,其中包含一个 JPanel,其中包含一个 JTextArea。我已经成功地将 System.out 指向 JTextArea,但是当我尝试使用 Scanner(System.in) 来解析来自 JTextArea 的输入时,它甚至似乎没有加载任何内容。例如,当我构建和运行应用程序时,什么也没有发生,也没有显示任何框架。这是我的代码:
java - 分离 System.Out 消息和扫描器 (Java)
有没有办法在不使用任何类型的 gui 包的情况下不让 System.out 将自己注入到提示符中间?
该场景是一个线程程序,您可以在其中向服务器发送和接收消息。
在写入服务器时,您会收到来自服务器的消息。
“我正在从服务器写消息”
所以你基本上最终会在你的控制台中看到类似的东西。
有没有办法绕过这个问题,并从本质上将提示与输入分开?
java - Java:如何读取未知大小的矩阵
我需要将矩阵从标准输入存储到 a[][] 中。(系统.in)
如果大小未知,如何初始化
请帮忙,谢谢
java - 无法从 System.in InputStreamReader 返回结果
我在返回颜色字符串时遇到了麻烦。由于某种原因,它不会返回数字。不确定我是否需要用 else 插入 if 语句的结尾,但我觉得 catch 语句 if 是什么意思。
主班
测试班
java - System.in 输入,java 但使用 apache ant
我以交互方式添加了一些 system.in 输入(用户输入)。我已经创建了可执行 jar,并且正在使用 apache ant 来编译和运行该程序。当我使用 java -jar jarfile.jar 执行它时,程序交互正常并通过缓冲读取器 system.in 获取用户输入,但是当我通过 ant run 通过 apache ant 运行它时,它在获取第一个输入后挂起。
为什么使用 apache ant,它不接受通过键盘输入的 System.in 输入?
我是否必须在 apache ant 的运行目标 java 任务中添加一些东西?
java - Java 2 lines terminal input
For a school assignment I have to make a program that reads two numbers from the terminal and then processes those numbers. The program has to automatically process those two values once they have been entered. The code I have so far is down below, but you have to press Enter before the program multiplies the numbers, the user shouldn't have to press enter three times, but only two times.
This is how the user has to use the program at the moment
- Enter number 1 and press enter
- Enter number 2 and press enter
- Enter nothing and press enter
- The program prints the multiplied numbers
But this is how the user should use the program at the moment:
- Enter number 1 and press enter
- Enter number 2 and press enter
- The program prints the multiplied numbers
Of course my program has to do something different for the assignment but I have changed it a little bit to make it easier to explain here.
Thank you for you help in advance!