Different Ways to Take Input from User in Java

There are mainly five different ways to take input from user in java using keyboard.

1. Command Line Arguments

2. BufferedReader and InputStreamReader Class

3. DataInputStream Class

4. Console Class

5. Scanner Class

 

Below I have shared example for each of them.

 

Different Ways to Take Input from User in Java

 

How to Take Input from User in Java

Command Line Arguments

It is one of the simplest way to read values from user. It will work only when you are running the program from command line.

 

BufferedReader and InputStreamReader Class

 

DataInputStream Class

 

Console Class

It will work only when you are running the program from command line.

 

Scanner Class

One of the most commonly used way to read from keyboard.

 

You can ask your queries in comment section.

Happy Coding!! 🙂 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *