console-input

What is the End Of File/Stream keyboard combination to use with System.in.read()

廉价感情. 提交于 2021-01-27 06:06:42
问题 Apologize if this trivial question has already been answered, I cannot find it at SO. Reading lines from the IDE console with this Java trivial code (Windows 7 and Eclipse Kepler): int v; try { while ((v = System.in.read()) != -1) System.out.println(v); } catch (IOException e) { ; } How the user can make the value v equal to -1? (I've tried Ctrl + d - z - x - c - s - e and other keys without repeatable behavior, but the loop is interrupted randomly) 回答1: Control + D should send the EOF

What is the End Of File/Stream keyboard combination to use with System.in.read()

﹥>﹥吖頭↗ 提交于 2021-01-27 06:04:59
问题 Apologize if this trivial question has already been answered, I cannot find it at SO. Reading lines from the IDE console with this Java trivial code (Windows 7 and Eclipse Kepler): int v; try { while ((v = System.in.read()) != -1) System.out.println(v); } catch (IOException e) { ; } How the user can make the value v equal to -1? (I've tried Ctrl + d - z - x - c - s - e and other keys without repeatable behavior, but the loop is interrupted randomly) 回答1: Control + D should send the EOF

Read numbers from the console given in a single line, separated by a space

耗尽温柔 提交于 2019-12-29 04:20:13
问题 I have a task to read n given numbers in a single line, separated by a space from the console. I know how to do it when I read every number on a separate line ( Console.ReadLine() ) but I need help with how to do it when the numbers are on the same line. 回答1: You can use String.Split. You can provide the character(s) that you want to use to split the string into multiple. If you provide none all white-spaces are assumed as split-characters(so new-line, tab etc): string[] tokens = line.Split()

Idiomatic way to write Clojure code for repeatedly reading lines from the console?

徘徊边缘 提交于 2019-12-20 12:34:27
问题 Recently I was writing a little CLI script which needed to repeatedly read dates from the console (the number of dates to read was calculated and could be different each time). Sample Ruby code to give you the idea: dates = x.times.collect { print "Enter date: "; Date.parse(gets.chomp) } Just for the heck of it, I wrote the script in Clojure, and wound up using some rather ugly code with swap! and loop...recur . I'm wondering what the cleanest way to achieve the desired effect in Clojure

Read numbers from the console given in a single line, separated by a space

一世执手 提交于 2019-11-28 21:35:51
I have a task to read n given numbers in a single line, separated by a space from the console. I know how to do it when I read every number on a separate line ( Console.ReadLine() ) but I need help with how to do it when the numbers are on the same line. You can use String.Split . You can provide the character(s) that you want to use to split the string into multiple. If you provide none all white-spaces are assumed as split-characters(so new-line, tab etc): string[] tokens = line.Split(); // all spaces, tab- and newline characters are used or, if you want to use only spaces as delimiter: