How to use readline() method in Java?

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

    I advise you to go with Scanner instead of DataInputStream. Scanner is specifically designed for this purpose and introduced in Java 5. See the following links to know how to use Scanner.

    • Java Documentation
    • Java Tutorial

    Example

    Scanner s = new Scanner(System.in);
    System.out.println(s.nextInt());
    System.out.println(s.nextInt());
    System.out.println(s.next());
    System.out.println(s.next());
    

提交回复
热议问题