質問編集履歴

3

一部表現を変更

2016/09/01 12:54

投稿

tetsukay
tetsukay

スコア232

test CHANGED
File without changes
test CHANGED
@@ -176,7 +176,7 @@
176
176
 
177
177
 
178
178
 
179
- ただ,指定しても動かない...
179
+ ただ,指定しても結果は変わらず...
180
180
 
181
181
 
182
182
 

2

StackOverflowで似た投稿を追記

2016/09/01 12:54

投稿

tetsukay
tetsukay

スコア232

test CHANGED
File without changes
test CHANGED
@@ -102,6 +102,10 @@
102
102
 
103
103
 
104
104
 
105
+ 追記1:
106
+
107
+
108
+
105
109
  http://www.javadrive.jp/start/scanner/index2.html
106
110
 
107
111
  上記サンプルプログラムをコピペしましたが,同様のエラーが出ています.
@@ -159,3 +163,49 @@
159
163
 
160
164
 
161
165
  ```
166
+
167
+
168
+
169
+ 追記2:
170
+
171
+
172
+
173
+ どうやらGradleだとstandardInputの指定が必要な様子.
174
+
175
+ http://stackoverflow.com/questions/36723447/java-util-scanner-throws-nosuchelementexception-when-application-is-started-with
176
+
177
+
178
+
179
+ ただ,指定しても動かない...
180
+
181
+
182
+
183
+ ```build.gradle
184
+
185
+ (略)
186
+
187
+ repositories {
188
+
189
+ mavenCentral()
190
+
191
+ }
192
+
193
+
194
+
195
+ run {
196
+
197
+ standardInput = System.in
198
+
199
+ }
200
+
201
+
202
+
203
+ dependencies {
204
+
205
+ testCompile group: 'junit', name: 'junit', version: '4.11'
206
+
207
+ }
208
+
209
+
210
+
211
+ ```

1

サンプルプログラムのコピペの実行結果と環境を追記

2016/09/01 12:53

投稿

tetsukay
tetsukay

スコア232

test CHANGED
File without changes
test CHANGED
@@ -99,3 +99,63 @@
99
99
 
100
100
 
101
101
  ```
102
+
103
+
104
+
105
+ http://www.javadrive.jp/start/scanner/index2.html
106
+
107
+ 上記サンプルプログラムをコピペしましたが,同様のエラーが出ています.
108
+
109
+ 環境の問題なんでしょうか.
110
+
111
+
112
+
113
+ OS: Ubuntu 16.04 x64
114
+
115
+ IDE: Intellij IDEA
116
+
117
+ Java: 1.8
118
+
119
+ Build tool: Gradle
120
+
121
+
122
+
123
+ ```java
124
+
125
+ public static void main(String[] args) {
126
+
127
+ try {
128
+
129
+ // new Main().start();
130
+
131
+ System.out.println("数値を入力して下さい。");
132
+
133
+
134
+
135
+ Scanner scan = new Scanner(System.in);
136
+
137
+
138
+
139
+ int val = scan.nextInt();
140
+
141
+ System.out.println("最初の数値のトークンは: "+ val);
142
+
143
+
144
+
145
+ val = scan.nextInt();
146
+
147
+ System.out.println("次の数値のトークンは : "+ val);
148
+
149
+
150
+
151
+ } catch (Exception e) {
152
+
153
+ e.printStackTrace();
154
+
155
+ }
156
+
157
+ }
158
+
159
+
160
+
161
+ ```