0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

数値のキーボード入力について質問です

Posted at
1 / 2

以下のコードの文字入力部分をBufferedReaderにすると正常に入力できないのですがなぜでしょうか
Scannerだと正常に動きます


		BufferedReader br = new 
                BufferedReader(newInputStreamReader(System.in));

		double max = Double.NEGATIVE_INFINITY;
		double min = Double.POSITIVE_INFINITY;
		double dat = 0;

		System.out.println(max + " " + min);

		for(int i = 0;i < 4;i++) {

			System.out.println("数値入力");

			dat = br.read(); //ここ

			if(dat > max) {
				max = dat;
			}
			if(dat < min) {
				min = dat;
			}

		}
		System.out.println("最大値:" + max + " " + " 最小値:" +min);

	}

BufferedReaderを使用した場合の実行結果↓

-Infinity Infinity
数値入力
1
数値入力
数値入力
数値入力
2
最大値:50.0 最小値:10.0

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?