How to use readline() method in Java?

前端 未结 5 1389
伪装坚强ぢ
伪装坚强ぢ 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:27

    In summary: I would be careful as to what code you copy. It is possible you are copying code which happens to work, rather than well chosen code.

    In intnumber, parseInt is used and in floatnumber valueOf is used why so?

    There is no good reason I can see. It's an inconsistent use of the APIs as you suspect.


    Java is case sensitive, and there isn't any Readline() method. Perhaps you mean readLine().

    DataInputStream.readLine() is deprecated in favour of using BufferedReader.readLine();

    However, for your case, I would use the Scanner class.

    Scanner sc = new Scanner(System.in);
    int intNum = sc.nextInt();
    float floatNum = sc.nextFloat();
    

    If you want to know what a class does I suggest you have a quick look at the Javadoc.

提交回复
热议问题