How to use readline() method in Java?

前端 未结 5 1356
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 16:17

I am beginner in Java, and I was reading the topic of giving values to variables through the readLine() method from the keyboard. The program for that is given

5条回答
  •  自闭症患者
    2020-11-27 16:46

    A DataInputStream is just a decorator over an InputStream (which System.in is) which allows to read using more convenient methods.

    As to the Float.valueOf(), well, that's curious because Float has .parseFloat() as well. Here the code grabs a Float with .valueOf() which it turns into the primitive float type using .floatValue(), which is unnecessary with Java 1.5+ due to auto unboxing.

    And as other answers rightly say, these methods are obsolete anyway.

提交回复
热议问题